maxvel
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
этот код рисует линию поверх поля rich text! я хочу нарисовать линию внизу каждой линии!
и этот код рисует линию в нижней части поля rich text, но не фиксируется
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
и этот код не был правдой
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)