Page 1 of 2

Merge cells

Posted: Fri Oct 03, 2014 10:58 am
by mohsen24000
Hi,
I have a table with 3 cols in row.
I want merge cells 1,2 together in rows 0,1,2 and merge cells 0,1 in rows 3,4,5 and again merge cells 1,2 in rows 6,7,8 and so on.
but when use
when row is 0,1,2,6,7,8
table.MergeCells(row,1,2,1,true);
when row is 3,4,5
table.MergeCells(row,0,2,1,true); <-- beep and does not work;
Please guide me :(

Posted: Fri Oct 03, 2014 12:07 pm
by Sergey Tkachenko
I tried:

Code: Select all

var table: TRVTableItemInfo;
begin
  table := TRVTableItemInfo.CreateEx(9, 3, RichViewEdit1.RVData);
  table.MergeCells(0, 1,2,1,true);
  table.MergeCells(1, 1,2,1,true);
  table.MergeCells(2, 1,2,1,true);

  table.MergeCells(3, 0,2,1,true);
  table.MergeCells(4, 0,2,1,true);
  table.MergeCells(5, 0,2,1,true);

  table.MergeCells(6, 1,2,1,true);
  table.MergeCells(7, 1,2,1,true);
  table.MergeCells(8, 1,2,1,true);

  table.CellBorderWidth := 1;
  RichViewEdit1.InsertItem('', table)

end;
This code works as expected.

Posted: Fri Oct 03, 2014 10:50 pm
by mohsen24000
Thanks a lot.
I want to implement chat room such as whatsapp.
my chats appear left and others in right.
is table suitable for this or bitmap generation!?

Posted: Sat Oct 04, 2014 9:19 am
by Sergey Tkachenko
Sorry, I do not understand the question

Posted: Sat Oct 04, 2014 9:59 am
by mohsen24000
Image

Posted: Sat Oct 04, 2014 10:07 am
by Sergey Tkachenko
I think using bitmaps is not a good idea, because users may want to copy-paste text.

I think you can use events for custom drawing.
For example, if you use tables, you can use OnDrawBorder.

Posted: Sat Oct 04, 2014 10:16 am
by mohsen24000
No problem for copy-paste text!
chats inserted into dbase and bitmap insert in TRichView with tag -> message id in dbase.
my issue is :
1- Speed 2- optimized implementation of the program

Posted: Sat Oct 04, 2014 10:20 am
by Sergey Tkachenko
I would implement it as a table with custom drawn background (in table.OnDrawBorder event).

Posted: Sun Oct 05, 2014 9:52 am
by mohsen24000
Please a little guidance!
thanks a lot :)

Posted: Sun Oct 05, 2014 5:37 pm
by Sergey Tkachenko
For example, you can use 1x1 table for each message, and draw table background.

Simple text for inserting table in RichViewEdit. This table shows rounded rectangle as a background:

Code: Select all

procedure TForm3.ToolButton68Click(Sender: TObject);
var table: TRVTableItemInfo;
begin
  table := TRVTableItemInfo.CreateEx(1,1, RichViewEdit1.RVData);
  table.OnDrawBorder := DrawTableBorder;
  RichViewEdit1.InsertItem('', table)
end;

procedure TForm3.DrawTableBorder(Sender: TRVTableItemInfo;
    Canvas: TCanvas; Left,Top,Right,Bottom: Integer;
    Width: TRVStyleLength;
    LightColor, Color, BackgroundColor: TColor;
    Style: TRVTableBorderStyle; Printing: Boolean;
    VisibleBorders: TRVBooleanRect; Row, Col: Integer;
    var DoDefault: Boolean);
begin
  if Row>=0 then
    exit;
  Canvas.Pen.Color := clRed;
  Canvas.Pen.Style := psSolid;
  Canvas.Pen.Width := 1;
  Canvas.Brush.Color := clYellow;
  Canvas.Brush.Style := bsSolid;
  Canvas.RoundRect(Left, Top, Right, Bottom, (Right-Left) div 2, (Bottom-Top) div 2);
  DoDefault := False;
end;
Some additional measures should be taken if cells can be edited, but, as I understand, you do not need editing these tables.

Note that OnDrawBorder for a table is called before drawing the table content, so it can be used for drawing background.

Posted: Sun Oct 05, 2014 8:41 pm
by mohsen24000
Thank you
unfortunately, when i want draw rounded background for cells, it's draw on content of cell, no behind! :(

if row<0 then
exit;

Posted: Mon Oct 06, 2014 3:45 pm
by Sergey Tkachenko
Which version of TRichView do you use?
Version 15 draws the border before content.

If you use older version, you can change the code drawing only on border areas, since balloon background is a plain text.

Posted: Mon Oct 06, 2014 4:54 pm
by mohsen24000
version 14
please guide , how do it!?

Posted: Mon Oct 06, 2014 5:40 pm
by Sergey Tkachenko
It's strange, I looked in the code of TRichView 14, it draws table border before (i.e. below) contents too.

Do you added the code

Code: Select all

if Row>=0 then 
    exit; 
?

Cell borders are drawn after (i.e. above) the cell content.

Posted: Mon Oct 06, 2014 6:05 pm
by mohsen24000
Problem is here!
I want draw rounded background for cells

if row<0 then
exit;