ImageEn, unit iexRichEdit

TIERichEdit.SetTableProperties

TIERichEdit.SetTableProperties


Declaration

function SetTableProperties(ColCount: Integer;
                            RowCount: Integer;
                            ColWidth: Integer = 100;
                            RowHeight: Integer = 0;
                            BorderSize: Integer = 1;
                            BorderColor: TColor = clBlack;
                            TableAlignment: TAlignment = taLeftJustify;
                            CellVertAlign: TVerticalAlignment = taAlignTop;
                            CellMargin: Integer = 4;
                            BackgroundColor: TColor = clWhite;
                            Indent: Integer = 0
                            ): Boolean;


Description

Modifies the properties of the currently selected table.
Result is false if there is not a table selected.

Note:
 RowCount should be specified as -1 to update the properties entire table
 If ColCount is different from the current count, cells will be added or deleted
 SetTableProperties() does not support row selection. The cursor should be positioned inside the first cell. If there is a selection, this will occur automatically
 You should initialize all variables using GetTableProperties

Rich Edit Identifier: EM_SETTABLEPARMS


Example

var
  colCount: Integer;
  rowCount: Integer;
  colWidth: Integer;
  rowHeight: Integer;
  tableAlign: TAlignment;
  cellVertAlign: TVerticalAlignment;
  borderSize: Integer;
  borderColor: TColor;
  cellMargin: Integer;
  bgColor: TColor;
  indent: Integer;
  initIndex: Integer;
begin
  // Works best if the cursor is positioned inside the first cell

  if IERichEdit1.SelLength = 0 then
  begin
    initIndex := IERichEdit1.SelStart;

    // GetTableProperties() requires whole row to be selected
    IERichEdit1.SelectAll( True );
  end
  else
    initIndex := IERichEdit1.SelStart + 2; // Whole row has been selected, position cursor inside the first cell

  // Get existing properties
  if IERichEdit1.GetTableProperties( colCount, rowCount,
                                     colWidth, rowHeight,
                                     borderSize, borderColor,
                                     tableAlign, cellVertAlign,
                                     cellMargin,
                                     bgColor,
                                     indent ) = False then
    raise Exception.create( 'You have not selected a table (click inside the first cell of the table)' );

  // Update background color to red
  bgColor := clRed;

  // Vertically align the text
  cellVertAlign := taVerticalCenter;

  // Make border color green
  borderColor := clGreen;

  // SettTableProperties() requires cursor to be positioned inside first cell, doesn't support row selection :-/
  if IERichEdit1.SelLength > 0 then
    IERichEdit1.SetSelection( initIndex, initIndex );

  // Update the properties
  if IERichEdit1.SetTableProperties( colCount,
                                     -1,     // Update whole table
                                     colWidth, rowHeight,
                                     borderSize, borderColor,
                                     tableAlign, cellVertAlign,
                                     cellMargin,
                                     bgColor,
                                     indent ) = False then
    raise Exception.create( 'Cannot set table properties' );
end;


See Also

 GetTableProperties
 InsertTable