Back to Devexpress

How to: Replace a Picture with Another Picture in the Rich Text Editor

windowsforms-403901-controls-and-libraries-rich-text-editor-examples-search-and-replace-how-to-replace-a-picture-with-another-picture.md

latest2.0 KB
Original Source

How to: Replace a Picture with Another Picture in the Rich Text Editor

  • May 29, 2023

The following example demonstrates how to use the PictureFormat.SetPicture method to replace a picture with another picture, and maintain the original format, size, and position.

csharp
Document document = richEditControl.Document;

// Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;

// Insert a picture.
Shape picture = document.Shapes.InsertPicture(document.Range.Start, DocumentImageSource.FromFile("Picture_Dog.png"));

// Set the picture size.
picture.Size = new SizeF(3f, 2.5f);

// Align the picture.
picture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
picture.VerticalAlignment = ShapeVerticalAlignment.Top;

// Change the picture's form.
picture.PictureFormat.Preset = ShapeGeometryPreset.RoundedRectangle;

// Display a border around the picture.
picture.Line.Color = Color.Black;

// Replace the picture.
picture.PictureFormat.SetPicture(DocumentImageSource.FromFile("Picture_Cat.png"));
vb
Dim document As Document = richEditControl.Document

' Set the measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch

' Insert a picture.
Dim picture As Shape = document.Shapes.InsertPicture(document.Range.Start, DocumentImageSource.FromFile("Picture_Dog.png"))

' Set the picture size.
picture.Size = New SizeF(3F, 2.5F)

' Align the picture.
picture.HorizontalAlignment = ShapeHorizontalAlignment.Center
picture.VerticalAlignment = ShapeVerticalAlignment.Top

' Change the picture's form.
picture.PictureFormat.Preset = ShapeGeometryPreset.RoundedRectangle

' Display a border around the picture.
picture.Line.Color = Color.Black

' Replace the picture.
picture.PictureFormat.SetPicture(DocumentImageSource.FromFile("Picture_Cat.png"))