Richtextbox : add autoline after blank line

Xancholy

Well-known member
Joined
Aug 29, 2006
Messages
143
Programming Experience
Beginner
In VB.Net's code editor when we type in say...
VB.NET:
Private Sub mysub()

End sub

The editor automatically places a line after End Sub.

How can I replicate that autoline in a richtextbox after each blank line ?

If MS can do it There has to be a way. Thanks
 

Attachments

  • editor line.jpg
    editor line.jpg
    11.1 KB · Views: 39
The following code adds a line drawing to the richtextbox when a newline is entered.

How can I position this line drawing to where a blank line is found ?

VB.NET:
    Private Sub RichTextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim myPen As New System.Drawing.Pen(Color.Black)
            Dim formGraphics As System.Drawing.Graphics

            formGraphics = RichTextBox1.CreateGraphics() 'the control where you want to paint the line
            formGraphics.DrawLine(myPen, 0, 0, Me.RichTextBox1.Width, 0)
            myPen.Dispose()
            formGraphics.Dispose()

        End If
    End Sub
 
The code below draws a line after every new line typed but gets wiped out when user continues typing.

How can I amend this code to draw a line after every blank line ?

VB.NET:
    Private Sub RichTextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyUp
        If e.KeyCode = Keys.Enter Then


            Dim myP As Point = RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart)
            Dim myPen As New System.Drawing.Pen(Color.Black)
            Dim formGraphics As System.Drawing.Graphics

            formGraphics = RichTextBox1.CreateGraphics() 'the control where you want to paint the line
            formGraphics.DrawLine(myPen, myP.X, myP.Y, Me.RichTextBox1.Width, myP.Y)
            myPen.Dispose()
            formGraphics.Dispose()
            TextBox1.Text = myP.Y & " " & myP.X
        End If
    End Sub
 
How can I code this condition ?
Every time I press enter check if there is any text at the beginning of the line.
If none, draw a line.
 
Back
Top