Drag n drop support to image effects

This commit is contained in:
Jaex 2013-11-12 08:35:44 +02:00
parent 9d42b58cb7
commit d4eada44b1
2 changed files with 47 additions and 0 deletions

View file

@ -249,6 +249,8 @@ private void InitializeComponent()
this.pbResult.Name = "pbResult";
this.pbResult.Size = new System.Drawing.Size(688, 448);
this.pbResult.TabIndex = 11;
this.pbResult.DragDrop += new System.Windows.Forms.DragEventHandler(this.pbResult_DragDrop);
this.pbResult.DragEnter += new System.Windows.Forms.DragEventHandler(this.pbResult_DragEnter);
//
// ImageEffectsForm
//

View file

@ -57,6 +57,7 @@ public ImageEffectsForm(Image img, List<ImageEffect> effects = null)
public void EditorMode()
{
pbResult.AllowDrop = true;
btnLoadImage.Visible = true;
btnSaveImage.Visible = true;
}
@ -340,6 +341,9 @@ private void btnLoadImage_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Browse for images...";
ofd.Filter = "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)|*.jpg;*.jpeg;*.png;*.gif;*.bmp";
if (ofd.ShowDialog() == DialogResult.OK)
{
if (DefaultImage != null) DefaultImage.Dispose();
@ -366,6 +370,47 @@ private void btnSaveImage_Click(object sender, EventArgs e)
}
}
private void pbResult_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) || e.Data.GetDataPresent(DataFormats.Bitmap, false))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void pbResult_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
string[] files = e.Data.GetData(DataFormats.FileDrop, false) as string[];
if (files != null && files.Length > 0)
{
if (Helpers.IsImageFile(files[0]))
{
if (DefaultImage != null) DefaultImage.Dispose();
DefaultImage = Helpers.GetImageFromFile(files[0]);
UpdatePreview();
}
}
}
else if (e.Data.GetDataPresent(DataFormats.Bitmap, false))
{
Image img = e.Data.GetData(DataFormats.Bitmap, false) as Image;
if (img != null)
{
if (DefaultImage != null) DefaultImage.Dispose();
DefaultImage = img;
UpdatePreview();
}
}
}
private void btnOK_Click(object sender, EventArgs e)
{
Effects = GetImageEffects();