Set table line style to dotted line

General TRichView support forum. Please post your questions here
Post Reply
luvcloud_say
Posts: 5
Joined: Thu Feb 08, 2007 12:50 am

Set table line style to dotted line

Post by luvcloud_say »

Hi,

I have created tables to be inserted in the TRichViewEdit component. Is there anyway I can set a table's line style to dotted line? Under the TRVTableItemInfo class, i can set the BorderStyle and BorderColor, but i would like the line style to be dotted instead of a solid line. Is that possible?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Only by drawing it yourself in table.OnDrawBorder event.
luvcloud_say
Posts: 5
Joined: Thu Feb 08, 2007 12:50 am

Post by luvcloud_say »

Ok, I'm trying the OnDrawBorder event as u said. I'm not sure what I did wrong, but it doesn't seem to call the OnDrawBorder event. Here's my code snippet.


procedure TForm1.Button2Click(Sender: TObject);
var
l_Status, l_Pos : Integer;
l_WideString : widestring;
l_RVTable : TRVTableItemInfo;
l_stream : TStringStream;
begin
WideString := u_RTFString;

l_RVTable := TRVTableItemInfo.CreateEx(1, 1, RichViewEdit2.RVData);

l_RVTable.OnDrawBorder := DrawBorderDo;

l_stream := TStringStream.Create('');
l_Stream.WriteString(l_WideString);
l_stream.Seek(0, soFromBeginning);
l_RVTable.Cells[0,0].LoadRTFFromStream(l_Stream);

RichViewEdit2.AddItem('x', l_RVTable);
RichViewEdit2.SaveRTF('C:\Testing.rtf', False);
l_Stream.free;
end;




procedure TForm1.DrawBorderDo(Sender: TRVTableItemInfo;
Canvas: TCanvas; Left,Top,Right,Bottom, Width: Integer;
LightColor, Color, BackgroundColor: TColor;
Style: TRVTableBorderStyle; Printing: Boolean;
VisibleBorders: TRVBooleanRect; Row, Col: Integer;
var DoDefault: Boolean);
begin
if Width=0 then
exit;
inc(Right);
inc(Bottom);
Canvas.Pen.Color := clRed;
Canvas.Pen.Style := psSolid;
Canvas.Pen.Width := 5;

Canvas.Brush.Style := bsSolid;
Canvas.Rectangle(Left,Top,Right,Bottom);
DoDefault := False;
end;



Do note that the code above doesnt draw a dotted line table yet, as I am just trying to see if the OnDrawBorder event is triggered. But I'm assuming that to draw dotted line, i just have to set the pen.Style = psDot rite?
So when i step through the codes, the event does not get triggered, and my rtf doc also doesnt show the table line in red color. Why was it not triggered?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Table events cannot be saved in files.

You need to reassign item events when table is inserted in the document.
Use OnItemAction event:

Code: Select all

procedure TForm3.RichViewEdit1ItemAction(Sender: TCustomRichView;
  ItemAction: TRVItemAction; Item: TCustomRVItemInfo; var Text: String;
  RVData: TCustomRVData);
begin
  if (ItemAction=rviaInserted) and (Item is TRVTableItemInfo) then
    TRVTableItemInfo(Item).OnDrawBorder := DrawBorderDo.
end;
Of course, this event will be called only when displaying this table in your application.
Post Reply