Hello,
currently I insert background images in tables over the table properties dialog. It works but it is not so useful for customers. Is there a way to insert background images via code? (like for pictures in tables: SRichViewEdit.ActiveEditor.InsertPicture('', Gr, rvvaBaseline)
Thanks!
Best Regards
Insert Background image in Tables via code
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Insert Background image in Tables via code
If you have a Table object, you can simply assign BackgroundImage property:
This code copies an image from gr, you still need to free gr.
However, if Table.BackgroundStyle = rvbsColor, this image will not be displayed. You need to assign rvbsStretched, rvbsTiled, or rvbsCentered.
The code below loads an image from a file, and assigns it as a background image for the current table in SRichViewEdit1.
Since there are two operations here (changing a background image and a background style), we group changes, so they can be undone as a single operation.
Code: Select all
Table.BackgroundImage := gr;
However, if Table.BackgroundStyle = rvbsColor, this image will not be displayed. You need to assign rvbsStretched, rvbsTiled, or rvbsCentered.
The code below loads an image from a file, and assigns it as a background image for the current table in SRichViewEdit1.
Since there are two operations here (changing a background image and a background style), we group changes, so they can be undone as a single operation.
Code: Select all
var
gr: TJPEGImage;
rve: TCustomRichViewEdit;
Table: TRVTableItemInfo;
begin
if not SRichViewEdit1.ActiveEditor.GetCurrentItemEx(
TRVTableItemInfo, rve, TCustomRVItemInfo(Table)) then
exit;
rve.BeginUndoGroup(rvutModifyItem);
rve.SetUndoGroupMode(True);
try
gr := TJPEGImage.Create;
try
gr.LoadFromFile('d:\Test\oldpaper.jpg');
Table.BackgroundImage := gr;
Table.BackgroundStyle := rvbsTiled;
finally
gr.Free;
end;
finally
rve.SetUndoGroupMode(False);
end;
rve.RefreshAll;
end;
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Insert Background image in Tables via code
If you want to change a cell background image, the code is similar.
A direct assignment (cannot be undone):
If you want to change as an editing operation (that can be undone), use SetCellBackgroundImage and SetCellBackgroundStyle instead:
A direct assignment (cannot be undone):
Code: Select all
Table.Cells[0, 0].BackgroundImage := gr;
Table.Cells[0, 0].BackgroundStyle := rvbsTiled;
Code: Select all
var
gr: TJPEGImage;
rve: TCustomRichViewEdit;
Table: TRVTableItemInfo;
begin
if not RichViewEdit1.GetCurrentItemEx(
TRVTableItemInfo, rve, TCustomRVItemInfo(Table)) then
exit;
rve.BeginUndoGroup(rvutModifyItem);
rve.SetUndoGroupMode(True);
try
gr := TJPEGImage.Create;
try
gr.LoadFromFile('d:\Test\oldpaper.jpg');
Table.SetCellBackgroundImage(gr, 0, 0);
Table.SetCellBackgroundStyle(rvbsTiled, 0, 0);
finally
gr.Free;
end;
finally
rve.SetUndoGroupMode(False);
end;
rve.RefreshAll;
end;
Re: Insert Background image in Tables via code
Hello Sergey,
thanks for your help! Works!
Best Regards
thanks for your help! Works!
Best Regards