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 ";
}
}