Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created August 17, 2018 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/daba6b5e439761c54ae0415103d18f72 to your computer and use it in GitHub Desktop.
Save bjoerntx/daba6b5e439761c54ae0415103d18f72 to your computer and use it in GitHub Desktop.
private void setLineNumbering()
{
textControl1.Refresh();
Graphics g = textControl1.CreateGraphics();
// iterates all lines
foreach (TXTextControl.Line line in textControl1.Lines)
{
// left position of current line minus offset
// so that the line number is displayed next to the current line
int left = line.TextBounds.X - LINE_START_OFFSET;
//top position of the current line
int top = line.TextBounds.Top;
//converts the positon of the current line to client coordinates
Point p = textControl1.DocumentToClient(new Point(left, top));
PointF pos = new PointF(p.X , p.Y);
//draws line number to the specified position
g.DrawString(line.Number.ToString() + ":",
new Font(textControl1.Font.Name, textControl1.Font.Size),
LINE_COLOR, pos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment