Merge cells

General TRichView support forum. Please post your questions here
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Merge cells

Post 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 :(
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post 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!?
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I do not understand the question
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post by mohsen24000 »

Image
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post 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
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I would implement it as a table with custom drawn background (in table.OnDrawBorder event).
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post by mohsen24000 »

Please a little guidance!
thanks a lot :)
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post 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;
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post by mohsen24000 »

version 14
please guide , how do it!?
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post by mohsen24000 »

Problem is here!
I want draw rounded background for cells

if row<0 then
exit;
Post Reply