RichTextBox with row number

Source: Internet
Author: User

 News introduction:Editorcontrol is a usercontrol that contains two controls: A RichTextBox (which can be used to display row numbers, such as labels) on the left, and a component -- editorgrid1 inherited from RichTextBox on the right.

Key words:
Editorcontrol is a usercontrol that contains two controls: A RichTextBox (which can be used to display row numbers, such as labels) on the left, and a component -- editorgrid1 inherited from RichTextBox on the right.

(1) Add events

Ditorgrid1.textchanged + = new eventhandler (editorgrid1_textchanged );
Editorgrid1.vscroll + = new eventhandler (editorgrid1_vscroll );

Void editorgrid1_vscroll (Object sender, eventargs E)
{
Int P = editorgrid1.getpositionfromcharindex (0). Y % (editorgrid1.font. height + 1 );
Richtextbox1.location = new point (0, P );
Drewlinenumber ();
}

Private void editorgrid1_textchanged (Object sender, eventargs E)
{
If (fchange)
{
RegEx r = new RegEx (@"/*");

If (! R. ismatch (parent. Text ))
{
Parent. Text + = "*";
}
}

Drewlinenumber ();
}

(2) Update the main function of the row number

Private void drewlinenumber ()
{
Point Pos = new point (0, 0 );
Int firstindex = editorgrid1.getcharindexfromposition (POS );
Int firstline = editorgrid1.getlinefromcharindex (firstindex );

POs. x = editorgrid1.clientrectangle. width;
POs. Y = editorgrid1.clientrectangle. height;

Int endindex = editorgrid1.getcharindexfromposition (POS );
Int endline = editorgrid1.getlinefromcharindex (endindex );

Richtextbox1.text = "";

For (INT I = firstline; I <= endline + 1; I ++)
{
Richtextbox1.text + = I + 1 + "/N ";
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.