Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Referencing <a href="https://stackoverflow.com/questions/124975/windows-forms-textbox-that-has-line-numbers#125093">Wayne's post</a>, here is the relevant code. It is using GDI to draw line numbers next to the text box.</p> <pre><code>Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call SetStyle(ControlStyles.UserPaint, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.DoubleBuffer, True) SetStyle(ControlStyles.ResizeRedraw, True) End Sub Private Sub RichTextBox1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.SelectionChanged FindLine() Invalidate() End Sub Private Sub FindLine() Dim intChar As Integer intChar = RichTextBox1.GetCharIndexFromPosition(New Point(0, 0)) intLine = RichTextBox1.GetLineFromCharIndex(intChar) End Sub Private Sub DrawLines(ByVal g As Graphics, ByVal intLine As Integer) Dim intCounter As Integer, intY As Integer g.Clear(Color.Black) intCounter = intLine + 1 intY = 2 Do g.DrawString(intCounter.ToString(), Font, Brushes.White, 3, intY) intCounter += 1 intY += Font.Height + 1 If intY &gt; ClientRectangle.Height - 15 Then Exit Do Loop End Sub Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) DrawLines(e.Graphics, intLine) End Sub Private Sub RichTextBox1_VScroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.VScroll FindLine() Invalidate() End Sub Private Sub RichTextBox1_UserScroll() Handles RichTextBox1.UserScroll FindLine() Invalidate() End Sub </code></pre> <p>The RichTextBox is overridden like this:</p> <pre><code>Public Class UserControl1 Inherits System.Windows.Forms.RichTextBox Public Event UserScroll() Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = &amp;H115 Then RaiseEvent UserScroll() End If MyBase.WndProc(m) End Sub End Class </code></pre> <p>(Code by divil on the xtremedotnettalk.com forum.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload