Click here to Skip to main content
14,453,354 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi
i want draw a line when press Enter key

like this


Hello World
___________________________
i am jack
___________________________
H r u jack?
___________________________


i cant :(

please help me
Posted
Updated 19-Nov-19 18:47pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi, this code works for me:

Private Sub RichTextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles RichTextBox1.KeyUp
    If e.KeyCode = Keys.Return Then
        RichTextBox1.AppendText("_______________")
        RichTextBox1.AppendText(Environment.NewLine)
    End If
End Sub


Have a nice day.
   
Comments
maxvel 20-Sep-13 7:41am
   
HI no no

no append text :S

Draw the Line!
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can also do that in javascript detect enter key and then append the line and new line.
Can you give me link to the demo of that rich text editor.
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

If you want to draw in a control use :

http://msdn.microsoft.com/fr-fr/library/system.windows.forms.control.creategraphics.aspx[^]

http://msdn.microsoft.com/fr-fr/library/system.drawing.graphics.aspx[^]


Exemple :

Dim gdi As Graphics = richTextBox1.CreateGraphics()
gdi.DrawLine(Pens.Black, new Point(0, (richTextBox1.Lines.Length + 1) * 10), new Point(50, (richTextBox1.Lines.Length + 1) * 10))
gdi.Dispose()
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 3

   
Rate this:
Please Sign up or sign in to vote.

Solution 7

Private Sub RichTextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
      ' Get current line number in RichTextBox
      Dim currentLine As Int32 = 0
      Dim P As Point = New Point(0)
      GetCaretPos(P)
      Dim Pos As Integer = Me.RichTextBox1.GetCharIndexFromPosition(P)
      currentLine = Me.RichTextBox1.GetLineFromCharIndex(Pos)

      ' Presume you manage to get line height and line space
      Dim lineHeight As Double
      Dim lineSpace As Double

      ' You can get current Y coordinate in RichTextBox
      Dim Y As Int32 = Math.Floor((lineHeight + lineSpace) * currentLine)

      If e.KeyCode = Keys.Enter Then

          Dim myPen As New System.Drawing.Pen(Color.Red)
          Dim formGraphics As System.Drawing.Graphics
          formGraphics = RichTextBox1.CreateGraphics()
          formGraphics.DrawLine(myPen, 0, Y, Me.RichTextBox1.Width, Y)
          myPen.Dispose()
          formGraphics.Dispose()
      End If

  End Sub



this code draw line on top of rich text box! i want draw line Bottom of each line!



and this code draw a line on bottom of rich text box but not Fixed


Dim currentLine As Int32 = 0

       Dim P As Point = New Point(0)

       GetCaretPos(P)

       Dim Pos As Integer = Me.RichTextBox1.GetCharIndexFromPosition(P)

       currentLine = Me.RichTextBox1.GetLineFromCharIndex(Pos)



       'MessageBox.Show(currentLine)

       ' Presume you manage to get line height and line space

       If currentLine > 0 Then

           Dim lineHeight As Double

           Dim lineSpace As Double



           ' You can get current Y coordinate in RichTextBox

           Dim Y As Int32 = Math.Floor((lineHeight + lineSpace) * currentLine)



           If e.KeyCode = Keys.Enter And RichTextBox1.Lines(currentLine - 1) = "" 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 If


and this code was not true

RichTextBox1.AppendText("HI")

       Dim gdi As Graphics = RichTextBox1.CreateGraphics()
       gdi.DrawLine(Pens.Black, New Point(0, (RichTextBox1.Lines.Length + 1) * 10), New Point(50, (RichTextBox1.Lines.Length + 1) * 10))
       gdi.Dispose()

       RichTextBox1.AppendText(vbNewLine)
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100