Hello DevExpress Support.
I am trying to find a property or method that allows me to determine the margins width for scaling images before inserting them into the document.
Can you advise if this is possible?
Regards
Jason Sullivan
Rescale Images programmatically prior to inserting into document
Answers approved by DevExpress Support
Hi Jason,
Thank you for contacting us. I am afraid that the XtraRichEdit does not have an event that fires when an image is inserted in a document. However, to accomplish your task, you can handle the RichEditControl.ContentChanged event with the following code:
C#private int count = 0;
private void Form1_Load(object sender, EventArgs e) {
DocumentImageCollection collection = richEditControl1.Document.GetImages(richEditControl1.Document.Range);
count = collection.Count;
}
private void richEditControl1_ContentChanged(object sender, EventArgs e) {
DocumentImageCollection collection = richEditControl1.Document.GetImages(richEditControl1.Document.Range);
if (collection.Count < count) {
count -= 1;
}
if (count != collection.Count && collection.Count != 0) {
DocumentImage documentImage = collection[collection.Count - 1];
SizeF size = documentImage.Size;
count = collection.Count;
}
}
Visual BasicPrivate count As Integer = 0
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim collection As DocumentImageCollection = richEditControl1.Document.GetImages(richEditControl1.Document.Range)
count = collection.Count
End Sub
Private Sub richEditControl1_ContentChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim collection As DocumentImageCollection = richEditControl1.Document.GetImages(richEditControl1.Document.Range)
If collection.Count < count Then
count -= 1
End If
If count <> collection.Count AndAlso collection.Count <> 0 Then
Dim documentImage As DocumentImage = collection(collection.Count - 1)
Dim size As SizeF = documentImage.Size
count = collection.Count
End If
End Sub
Please try this solution and let us know the results.
Thanks,
Sergi