i convert these sub from VB6 to VB2010:
(i get the SelectionLineSpacing from SendMessage() API function)
heres the sub for change the line spacing:
but my problem is how to print the numbers by line spacing position:(
can anyone advice me for correct the WriteNumbers sub?
Code:
Private Sub WriteLineNumbers()
' write the line numbers in the picture box..
' nice and quick way with the Print method.., ie.. no fancy crap, this works nicely.
' only print from the bounds of the top of the page to the bottom.. this way it
' takes no time at all!!
Dim x As Long
Dim lStart As Long
Dim FontHeight As Long
Dim lFinish As Long
Const EM_GETFIRSTVISIBLELINE = &HCE
Dim posY As Integer = 1
lStart = SendMessage(New HandleRef(Me, Me.Handle), EM_GETFIRSTVISIBLELINE, 0, 0) + 1
picNumbers.Font = Me.Font
picNumbers.ForeColor = Color.Blue
picNumbers.BackColor = Color.BlueViolet
FontHeight = picNumbers.Font.Height
lFinish = (Me.Height / FontHeight) + lStart
If lFinish > Me.Lines.Length Then lFinish = Me.Lines.Length
Dim myGraphics As Graphics = picNumbers.CreateGraphics
' loop from the first visible line in the rtb to the end of the page
myGraphics.Clear(picNumbers.BackColor)
For x = lStart To lFinish
myGraphics.DrawString(x.ToString, Me.Font, Brushes.Blue, 0, posY)
posY += Me.SelectionLineSpacing
Next x
myGraphics.Dispose()
End Sub
Code:
Public Property SelectionLineSpacing As Byte
Get
SendMessage(New HandleRef(Me, Me.Handle), EM_GETPARAFORMAT, 1, Para)
Return Para.bLineSpacingRule
End Get
Set(ByVal value As Byte)
SelLineSpacing(Me, value)
End Set
End Property
'Para is from Paraformat2 struture
Code:
Private Sub SelLineSpacing(ByVal rtbTarget As RichTextBox, ByVal SpacingRule As Byte, Optional ByVal LineSpacing As Integer = 20)
With Para
ReDim .rgxTabs(31)
.cbSize = CUInt(Marshal.SizeOf(Para))
.dwMask = PFM_LINESPACING
.bLineSpacingRule = SpacingRule
.dyLineSpacing = LineSpacing
End With
Dim result As Integer = SendMessage(New HandleRef(rtbTarget, rtbTarget.Handle), EM_SETPARAFORMAT, 1, Para)
If result = 0 Then
MessageBox.Show("EM_SETPARAFORMAT Failed")
End If
End Sub
can anyone advice me for correct the WriteNumbers sub?