windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitempictureedit-66e727ae.md
Allows you to execute actions when a user loads a file via the control’s context menu. You can handle this event to perform image preprocessing or to load images stored in unsupported formats.
Namespace : DevExpress.XtraEditors.Repository
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event ImageLoadEventHandler ImageLoading
<DXCategory("Events")>
Public Event ImageLoading As ImageLoadEventHandler
The ImageLoading event's data class is DevExpress.XtraEditors.Repository.SaveLoadImageEventArgs.
A user can load and save images at runtime via the context menu’s Load and Save commands (see ShowMenu). These commands invoke the Open File and Save File dialogs.
After a user selects a file in these dialogs, the PictureEdit control fires the ImageLoading event (to load an image) and ImageSaving event (to save an image).
The ImageLoading and ImageSaving events allow you to pre-process images. You can also handle these events to load and save image formats not supported in .NET Framework.
The ImageLoading event fires after the user selects and confirms a file in the Open File dialog. This event has the following arguments:
The ImageSaving event fires after the user confirms a file name in the Save File dialog. This event allows you to pre-process the image, convert it to a custom image format, and save it to the specified file.
Tip
Use the OpenFileDialogFilter and SaveFileDialogFilter properties to customize filters for the Open File and Save File dialogs.
The following example shows how to use the ImageLoading and ImageSaving events to convert images when they are loaded and saved.
private void Form1_Load(object sender, EventArgs e) {
pictureEdit1.Properties.OpenFileDialogFilter = "WebP Files |*.webp|" + "Portable Network Graphics Format (*.png)|*.png";
pictureEdit1.Properties.SaveFileDialogFilter = pictureEdit1.Properties.OpenFileDialogFilter;
}
private void pictureEdit1_Properties_ImageLoading(object sender, DevExpress.XtraEditors.Repository.SaveLoadImageEventArgs e) {
FileInfo fi = new FileInfo(e.FileName);
string fileExtension = fi.Extension.ToLower();
if (fileExtension == ".webp") {
e.Image = CustomConvertFromWebP(e.FileName);
e.Handled = true;
}
}
private void pictureEdit1_Properties_ImageSaving(object sender, DevExpress.XtraEditors.Repository.SaveLoadImageEventArgs e) {
FileInfo fi = new FileInfo(e.FileName);
string fileExtension = fi.Extension.ToLower();
if (fileExtension == ".webp") {
CustomSaveToWebP(e.Image, e.FileName);
e.Handled = true;
}
}
private Image CustomConvertFromWebP(string fileName) {
//...
}
private void CustomSaveToWebP(Image image, string fileName) {
//...
}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureEdit1.Properties.OpenFileDialogFilter = "WebP Files |*.webp|" & "Portable Network Graphics Format (*.png)|*.png"
PictureEdit1.Properties.SaveFileDialogFilter = PictureEdit1.Properties.OpenFileDialogFilter
End Sub
Private Sub PictureEdit1_Properties_ImageLoading(sender As Object, e As DevExpress.XtraEditors.Repository.SaveLoadImageEventArgs) Handles PictureEdit1.Properties.ImageLoading
Dim fi As FileInfo = New FileInfo(e.FileName)
Dim fileExtension As String = fi.Extension.ToLower()
If fileExtension = ".webp" Then
e.Image = CustomConvertFromWebP(e.FileName)
e.Handled = True
End If
End Sub
Private Sub PictureEdit1_Properties_ImageSaving(sender As Object, e As DevExpress.XtraEditors.Repository.SaveLoadImageEventArgs) Handles PictureEdit1.Properties.ImageSaving
Dim fi As FileInfo = New FileInfo(e.FileName)
Dim fileExtension As String = fi.Extension.ToLower()
If fileExtension = ".webp" Then
CustomSaveToWebP(e.Image, e.FileName)
e.Handled = True
End If
End Sub
Private Function CustomConvertFromWebP(ByVal fileName As String) As Image
'...
End Function
Private Sub CustomSaveToWebP(ByVal image As Image, ByVal fileName As String)
'...
End Sub
See Also
RepositoryItemPictureEdit Class