<< Click to display table of contents >> TRVTableItemInfo.OnDrawBorder |
Allows custom drawing of table borders
type
TRVTableDrawBorderEvent = procedure (Sender: TRVTableItemInfo;
Canvas: TCanvas; Left,Top,Right,Bottom: TRVCoord;
Width: TRVStyleLength;
LightColor, Color, BackgroundColor: TRVColor;
Style: TRVTableBorderStyle; Printing: Boolean;
VisibleBorders: TRVBooleanRect; Row, Col: Integer;
var DoDefault: Boolean) of object;
property OnDrawBorder: TRVTableDrawBorderEvent;
(introduced in version 1.7, modified in 1.8)
Input parameters
Sender – the table to draw border for (border can be drawn for the table itself or for the table cells).
Canvas – canvas where to draw.
Left, Top, Right, Bottom – rectangle for the border.
Width – border width, in Sender.Style.Units.
LightColor, Color, BackgroundColor – colors for border and for background (be careful - cell border is drawn after drawing cell content)
Style – border style.
Printing – True if this drawing is for printing; False if on screen.
VisibleBorders – VisibleBorders property for the table, or VisibleBorders property for the cell.
Row, Col – row and column of the cell (or -1 if this is a table border).
Output parameters
DoDefault – set to False to cancel the default border drawing.
For example,
{ Drawing a hairline border (both on screen and printer),
assuming that CellBorderWidth=1, CellVSpacing=0, CellHSpacing=0.
This example ignores VisibleBorders.
}
procedure TMyForm.DoDrawBorder(Sender: TRVTableItemInfo;
Canvas: TCanvas; Left, Top, Right, Bottom: TRVCoord;
Width: TRVStyleLength;
LightColor, Color, BackgroundColor: TRVColor;
Style: TRVTableBorderStyle;
Printing: Boolean; VisibleBorders: TRVBooleanRect;
var DoDefault: Boolean);
begin
if Width=0 then
exit;
inc(Right);
inc(Bottom);
Canvas.Pen.Color := Color;
Canvas.Pen.Style := psInsideFrame;
Canvas.Pen.Width := 1;
Canvas.Brush.Style := bsClear;
Canvas.Rectangle(Left,Top,Right,Bottom);
DoDefault := False;
end;
Tables are not components, so their events cannot be assigned at design time in the Object Inspector. They must be assigned in code. Events are not saved in RVF files, so you need to reassign them when tables are loaded. The best place to assign this event is TRichView.OnItemAction event.
// MyRichViewEdit.OnItemAction. Assigns DoDrawBorder to
// OnDrawBorder events of all tables inserted in MyRichViewEdit.
// (this assignment occurs when table is inserted using
// AddItem or InsertItem methods, or is loaded from RVF or RTF file)
procedure TMyForm.MyRichViewEditItemAction(Sender: TCustomRichView;
ItemAction: TRVItemAction; Item: TCustomRVItemInfo;
var Text: TRVUnicodeString; RVData: TCustomRVData);
begin
if (Item.StyleNo = rvsTable) and (ItemAction = rviaInserting) then
TRVTableItemInfo(Item).OnDrawBorder := DoDrawBorder;
end;
See also