Hi, I'm trying to get the height of a RichEditDocument based on its contents.
I have found that RichEditControl has a method named GetPixelPhysicalBounds, which I think it may be helpful, but I cannot find any documentation about how to use it.
Any suggestions?
Thanks!
Christian Llanos
GetPixelPhysicalBounds - Get Document height in pixels
Answers approved by DevExpress Support
Christian,
Thank you for the update. Basically, the WinForms classes might be utilized in the WPF environment in exceptional cases. As for the GetPixelPhysicalBounds() method, I am afraid that it is used only internally. That is why this method is not described in our documentation. As an alternative, documented solution, I can only suggest that you use the RichEditControl.GetBoundsFromPosition Method as follows to accomplish a similar task:
C#System.Drawing.Rectangle rect = richEditControl1.GetBoundsFromPosition(richEditControl1.Document.CreatePosition(richEditControl1.Document.Range.End.ToInt() - 1));
System.Drawing.Rectangle rectPix = DevExpress.XtraRichEdit.Utils.Units.DocumentsToPixels(rect,
richEditControl1.DpiX, richEditControl1.DpiY);
int height = rectPix.Bottom;
Hopefully, you will find this information helpful.
Thanks,
Alessandro.
Is this also possible for a XRRichTextEdit control? I'd like to be able to get the bounds for HTML content of a rich text edit that is able to grow vertically for a given width.
Hello Jules,
To process your recent post more efficiently, I created a separate ticket on your behalf: How to get size of the HTML content displayed in XRRichText. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.
Hello Christian,
I believe that you can use the approach from the Content size ticket for this purpose. Please let us know whether this approach is appropriate for you.
Thanks,
Alessandro.
Hi Alessandro,
I have reviewed that link and I'm not sure what approach should I take. It seems to me that the link you suggested is for Winforms, I'm currently working with WPF.
What about GetPixelPhysicalBounds? what and how is this used for?
Regards,
Christian Llanos
I think I have found a possible solution:
double height = 0.0;
DevExpress.XtraRichEdit.DocumentLayoutUnit oldUnit = this.LayoutUnit;
if (this.LayoutUnit != DevExpress.XtraRichEdit.DocumentLayoutUnit.Pixel) this.LayoutUnit = DevExpress.XtraRichEdit.DocumentLayoutUnit.Pixel;
System.Drawing.Rectangle rect = this.GetLayoutLogicalBoundsFromPosition(this.Document.CreatePosition(this.Document.Range.End.ToInt() - 1));
height = rect.Y + rect.Height;
if (this.LayoutUnit != oldUnit) this.LayoutUnit = oldUnit;
Regards,
Christian Llanos