Discussion:
Rich Text Box - Line Numbers
(too old to reply)
Jeff Gaines
2010-01-21 16:38:51 UTC
Permalink
I want to show line numbers in a control which is derived from a WinForms
RTB control. I am using:

private void SetLineNumbers()
{
PARAFORMAT2 paraFormat = new PARAFORMAT2();

paraFormat.cbSize = (UInt32)Marshal.SizeOf(paraFormat);

// Get existing format
SendMessage(this.Handle, EM.EM_GETPARAFORMAT, 0, ref paraFormat);

// Set flags
paraFormat.dwMask = (int)(PFM.PFM_NUMBERING | PFM.PFM_NUMBERINGSTYLE |
PFM.PFM_NUMBERINGSTART);
paraFormat.wNumbering = (UInt16)NUMBERING.Arabic;
paraFormat.wNumberingStart = 0;
paraFormat.wNumberingStyle = (UInt16)NUMBERINGSTYLES.NumberOnly;

SendMessage(this.Handle, EM.EM_SETPARAFORMAT, 0, ref paraFormat);
}

It works to the extent that I do get line numbers in theleft margin but
they stop at 254. If I paste text in then 254 is just repeated for all the
higher lines, if I type lines in I just get a blank.

Is there a way round this?

I have looked at some custom RTBs on the Internet and they seem to use
lables or panels to the left of the RTB. I have alos looked at the Sharp
Edit source but that is massive overkill for what I want.

Would appreciate any guidance.
--
Jeff Gaines Dorset UK
The facts, although interesting, are irrelevant
Herfried K. Wagner [MVP]
2010-01-22 00:17:58 UTC
Permalink
Post by Jeff Gaines
I want to show line numbers in a control which is derived from a
private void SetLineNumbers()
{
PARAFORMAT2 paraFormat = new PARAFORMAT2();
paraFormat.cbSize = (UInt32)Marshal.SizeOf(paraFormat);
// Get existing format
SendMessage(this.Handle, EM.EM_GETPARAFORMAT, 0, ref paraFormat);
// Set flags
paraFormat.dwMask = (int)(PFM.PFM_NUMBERING | PFM.PFM_NUMBERINGSTYLE |
PFM.PFM_NUMBERINGSTART);
paraFormat.wNumbering = (UInt16)NUMBERING.Arabic;
paraFormat.wNumberingStart = 0;
paraFormat.wNumberingStyle = (UInt16)NUMBERINGSTYLES.NumberOnly;
SendMessage(this.Handle, EM.EM_SETPARAFORMAT, 0, ref paraFormat);
}
It works to the extent that I do get line numbers in theleft margin but
they stop at 254. If I paste text in then 254 is just repeated for all
the higher lines, if I type lines in I just get a blank.
Is there a way round this?
I doubt that there is an easy way around that using the approach you
have chosen. Paragraph numbering is typically used to create numbered
/lists/.
Post by Jeff Gaines
I have looked at some custom RTBs on the Internet and they seem to use
lables or panels to the left of the RTB.
I assume that those are better approaches.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jeff Gaines
2010-01-23 09:24:41 UTC
Permalink
Post by Herfried K. Wagner [MVP]
I assume that those are better approaches.
Horribly complicated just to get line numbers but seems like the only way.

Many thanks Herfried :-)
--
Jeff Gaines Dorset UK
I can please only one person per day. Today is not your day.
Tomorrow, isn't looking good either.
Loading...