At my work, we have built our on custom label built using TRichView. We are using the TRVReportHelper to paint to the label's canvas. It has become necessary to identify the width and height of the content being painted so that we can calculate the size to make the label.
Currently, we successfully calculate the height of the content by painting to a temporary bitmap and returning RVReportHelper.GetLastPageHeight.
Now, I am working on calculating the width. Assuming the following guidelines are always true, what is the best way to do this:
- The content will not word wrap. It will consume only one line.
- The content will not contain any non-text items.
Calculating Content Width
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
This always returns the width of the bitmap's canvas. For future reference, I was able to solve this one via:
Code: Select all
Width := rvh.RichView.LeftMargin + rvh.RichView.RightMargin;
for I := 0 to rvh.RichView.RVData.DrawItems.Count - 1 do
Width := Width + rvh.RichView.RVData.DrawItems[I].Width;
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Use this code:
Code: Select all
Width := 0;
for I := 0 to rvh.RichView.RVData.DrawItems.Count - 1 do
if rvh.RichView.RVData.DrawItems[I].Left+rvh.RichView.RVData.DrawItems[I].Width>Width then
Width := rvh.RichView.RVData.DrawItems[I].Left+rvh.RichView.RVData.DrawItems[I].Width;
inc(Width, rvh.RichView.RightMargin);