RichTextBox技巧之插入表格

Properties - all sizes are in twips
 xLeft - Position of the left edge of the table
 isCentered - Set to True to center the table
 Rows - Sets or returns the number of rows in the table
 Columns - Sets or returns the number of columns in the table
 Row - An Array of Rows (1 to Rows)
 Column - An Array of columns (1 to Columns)
  Column(i).xWidth - Width of the ith column
 Cell - A 2-d Array of Cells (1 to Rows, 1 to Columns)
  Cell(r, c).Contents - Sets or returns the contents of the cell

Methods
 InsertTable(RTB As RichTextBox) - Inserts the table into the RichTextBox
                         at the currrent cursor position.

代码下载地址:
http://www.applevb.com/RTFtable.zip

使用范例:

Option   Explicit

Dim  RTFtable  As  clsRTFtable
Private   Declare   Function LockWindowUpdate Lib "user32" ( _
    
ByVal hwndLock As Long _
As Long

Private Sub Command1_Click()
  
Dim i As Integer
  
Set RTFtable = New clsRTFtable
  
'stop flicker
  Call LockWindowUpdate(RichTextBox1.hWnd)
  
  
For i = 1 To 5
  
With RTFtable
    
'set the size of the table
    .Columns = 3
    .Rows 
= 2
    
'fill the cells
    'Row 1
    .Cell(11).Contents = "Row 1"
    .Cell(
12).Contents = "Column2"
    .Cell(
13).Contents = "Column3"

    
'Row 2
    .Cell(21).Contents = "Row2"
    .Cell(
22).Contents = "R2C2"
    .Cell(
23).Contents = "R2C3"
    
'do we want to center it on the page?
    .isCentered = True
    
    
'insert the table at the current cursor postion
    .InsertTable RichTextBox1
  
End With
  
Next i
    
Call LockWindowUpdate(0)

End Sub

你可能感兴趣的:(text)