Results 1 to 40 of 162

Thread: RichTextBox Tricks and Tips

Threaded View

  1. #4

    Thread Starter
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Insert Tables

    Another useful functionality that can be added to the RichTextBox controls is the ability to insert tables.
    The RichTextBox controls support a limited subset of the table related Rich Text Format tags, but none
    of that is made accessible to users of the control. I've attached a class that you can use to insert tables
    into your RichTextBox controls.


    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.
    An example of use is
    Code:
    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(1, 1).Contents = "Row 1"
        .Cell(1, 2).Contents = "Column2"
        .Cell(1, 3).Contents = "Column3"
    
        'Row 2
        .Cell(2, 1).Contents = "Row2"
        .Cell(2, 2).Contents = "R2C2"
        .Cell(2, 3).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
    Attached Files Attached Files
    Last edited by moeur; Mar 12th, 2007 at 08:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width