picture alignment in table cell

General TRichView support forum. Please post your questions here
Post Reply
intis
Posts: 11
Joined: Mon Mar 23, 2009 7:45 pm

picture alignment in table cell

Post by intis »

Hi,
I insert a picture from clipboard into a table cell, in principle as follows:
Chart->CopyToClipboardMetafile(true) ;
TClipboard *pCB = Clipboard();
Graphics::TMetafile *pMetafile = new Graphics::TMetafile();
pMetafile->Assign(pCB);
Cell = table->Cells[1][1];
Cell->AddPictureEx("", pMetafile ,0, rvvaAbsMiddle);

But the picture does not fully fill the table cell; I have to manually enlarge it in order to fully fill the cell with the picture (similiar to Alignment=alClient in Delphi/CB).

How could I accomplish this programmically (without playing with pixels) ?

Thank you for a short note !
Best regards
Intis
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You can set the cell width to some small value (using its BestWidth property), and the cell will have the width of its content.
intis
Posts: 11
Joined: Mon Mar 23, 2009 7:45 pm

Post by intis »

Hmm, the cell width is already determied to 80% of page width (in order to get a good visible graph).
Does your answer mean, that I also could enlarge the picture much larger than the cell ?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Cells are always wide enough to show their content (unless you include rvtoIgnoreContentWidth and/or rvtoIgnoreContentHeight in table.Options).
If you specify too small BestWidth, the column will be widened to show the whole picture in the cell.

The picture cannot be automatically resized to fill the cell. Only the cell can be resized to the size of the picture. If you want to resize a picture, do it manually (either by changing the picture itself or by assigning rvepImageWidth and rvepImageHeight properties for the picture item).
intis
Posts: 11
Joined: Mon Mar 23, 2009 7:45 pm

Post by intis »

I tried it as follows:
Cell->Clear();
Cell->BestWidth = -79;
Cell->AddPictureEx("", pMetafile ,0, rvvaAbsMiddle);// rvvaBaseline);
//int w = Cell->GetWidth(); // returns -6
int w = Cell->GetAreaWidth(); // returns -6
Cell->SetItemExtraIntProperty(Cell->ItemCount-1, rvepImageWidth, w);
Cell->Format(true);

Nevertheless, the format of the picture within the cell seems unchanged.
Where is my mistake ?
Thank you for a hint !
Best regards
Intis
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

GetAreaWidth is an internal function, and it returns a valid value only if the document is formatted. Document can be formatted only when it is ready (all items are added), so you cannot use this function for assigning item width.
So I suggest to estimate a desired picture width basing on RichViewEdit->ClientWidth.
intis
Posts: 11
Joined: Mon Mar 23, 2009 7:45 pm

Post by intis »

Thank you for the hint - it helped !

- and how to get a usable value for the cell's height ?

(In the concrete case, it will depend on the height of contents inserted in other columns of the same row.)

Thank you !
Best regards
Intis
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You cannot get cell/row height until it is formatted...

One idea: may be you can assign this picture a background image for the cell? In this case, it can be stretched to the cell size. See BackgroundImage and BackgroundStyle properties.
Post Reply