# 请问 VB 高手 , richtextbox 控制项问题 ?

Posted by Linkii on February 05, 1999 at 12:32:40:

我想利用 RichTextBox 控制项,做 4 个栏位的格式定位,
分别起始位置为 20 , 140 , 260 ,380 (Pixels) ,请问下列程式有错误 .
谢谢 !

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_USER = &H400
Private Const EM_SETPARAFORMAT = WM_USER + 71
Private Const PFM_TABSTOPS = &H10

Private Type ParaFormat
cbsize As Byte
dwMask As Long
wNumbering As Integer
wReserved As Integer
dxStartIndent As Long
dxRightIndent As Long
dxOffset As Long
wAligment As Integer
cTabCount As Byte
rgxTabs() As Long
End Type

Dim StructFormat As ParaFormat

Private Sub Command1_Click()
Dim result As Long
result = SendMessage(Text1.hwnd, EM_SETPARAFORMAT, 0, StructFormat)
Text1.Text = Chr(9) & "the" & Chr(9) & "is" & Chr(9) & "a" & Chr(9) & "dog" & vbCrLf
Text1.Text = Text1.Text & Chr(9) & "te" & Chr(9) & "i" & Chr(9) & "afdf" & Chr(9) & "dog" & vbCrLf
Me.Caption = result
End Sub

Private Sub Form_Load()
StructFormat.cbsize = Len(StructFormat)
StructFormat.dwMask = PFM_TABSTOPS
StructFormat.cTabCount = 4
ReDim StructFormat.rgxTabs(3) As Long
StructFormat.rgxTabs(0) = 20
StructFormat.rgxTabs(1) = 140
StructFormat.rgxTabs(2) = 260
StructFormat.rgxTabs(3) = 380
End Sub

Follow Ups: