Page 1 of 1
picture alignment in table cell
Posted: Wed May 13, 2009 2:03 pm
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
Posted: Wed May 13, 2009 4:00 pm
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.
Posted: Wed May 13, 2009 8:08 pm
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 ?
Posted: Thu May 14, 2009 11:55 am
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).
Posted: Sun May 17, 2009 7:20 pm
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
Posted: Mon May 18, 2009 6:21 pm
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.
Posted: Mon May 18, 2009 7:03 pm
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
Posted: Mon May 18, 2009 7:09 pm
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.