Hello,
If someone can help plz.
I have searched everything and all I can find is how to drag and drop within a form from panel to panel.
What I need to do is Drag an image from the desktop or from an open folder to a panel on my form.
This will be done for a few images and then on Buttonclik I need to save each image in its own folder.
Any help is much appreciated.
Here is what I have on the events - for d&d
This allows me to drag and drop within the form but trying to drag from desktop to panel1 doesn't work. -
private void panel_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
-
}
-
-
-
-
-
private void panel_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
-
}
-
-
-
private void panel_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
-
-
}
-
6 6429
I have added a panel and a open dialog that paints an image in the panel but I cannot drag the image to any other panels.
With what I have here I can drag and drop in the same form.
I cannot drag from the image opened in panel1 from the loadbutton. -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace OpeninPanel
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private Bitmap m_Bitmap = null;
-
-
private void m_LoadButton_Click( object sender, EventArgs e )
-
{
-
if( m_OpenFileDialog.ShowDialog( this ) == DialogResult.OK )
-
{
-
m_Bitmap = new Bitmap( m_OpenFileDialog.FileName );
-
-
m_PaintPanel.SuspendLayout();
-
m_PaintPanel.Controls.Clear();
-
-
Panel panel = new Panel();
-
//int left = 0, top = 0;
-
//if( m_Bitmap.Width < m_PaintPanel.Width )
-
//{
-
// left = ( m_PaintPanel.Width - m_Bitmap.Width ) / 2;
-
// }
-
// if( m_Bitmap.Height < m_PaintPanel.Height )
-
// {
-
// top = (m_PaintPanel.Height - m_Bitmap.Height) / 2;
-
// }
-
panel.Size = m_Bitmap.Size;
-
// panel.Location = new Point( left, top );
-
panel.Paint += new System.Windows.Forms.PaintEventHandler( this.m_PaintPanel_Paint );
-
m_PaintPanel.Controls.Add( panel );
-
-
m_PaintPanel.ResumeLayout();
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
}
-
-
private void m_PaintPanel_Paint( object sender, PaintEventArgs e )
-
{
-
if( m_Bitmap != null )
-
{
-
e.Graphics.DrawImageUnscaled( m_Bitmap, 0, 0 );
-
}
-
}
-
-
/// <summary>
-
/// Required designer variable.
-
/// </summary>
-
private System.ComponentModel.IContainer components = null;
-
-
/// <summary>
-
/// Clean up any resources being used.
-
/// </summary>
-
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
-
-
-
#region Windows Form Designer generated code
-
-
/// <summary>
-
/// Required method for Designer support - do not modify
-
/// the contents of this method with the code editor.
-
/// </summary>
-
private void InitializeComponent()
-
{
-
this.m_PaintPanel = new System.Windows.Forms.Panel();
-
this.m_LoadButton = new System.Windows.Forms.Button();
-
this.m_OpenFileDialog = new System.Windows.Forms.OpenFileDialog();
-
this.panel1 = new System.Windows.Forms.Panel();
-
this.panel2 = new System.Windows.Forms.Panel();
-
this.panel3 = new System.Windows.Forms.Panel();
-
this.panel2.SuspendLayout();
-
this.SuspendLayout();
-
//
-
// m_PaintPanel
-
//
-
this.m_PaintPanel.AllowDrop = true;
-
this.m_PaintPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-
| System.Windows.Forms.AnchorStyles.Left)
-
| System.Windows.Forms.AnchorStyles.Right)));
-
this.m_PaintPanel.BackColor = System.Drawing.Color.Transparent;
-
this.m_PaintPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
-
this.m_PaintPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
-
this.m_PaintPanel.Location = new System.Drawing.Point(273, 107);
-
this.m_PaintPanel.Name = "m_PaintPanel";
-
this.m_PaintPanel.Size = new System.Drawing.Size(121, 190);
-
this.m_PaintPanel.TabIndex = 0;
-
this.m_PaintPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.m_PaintPanel_MouseDown);
-
this.m_PaintPanel.DragDrop += new System.Windows.Forms.DragEventHandler(this.m_PaintPanel_DragDrop);
-
this.m_PaintPanel.DragEnter += new System.Windows.Forms.DragEventHandler(this.m_PaintPanel_DragEnter);
-
this.m_PaintPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.m_PaintPanel_Paint_1);
-
//
-
// m_LoadButton
-
//
-
this.m_LoadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
-
this.m_LoadButton.Location = new System.Drawing.Point(299, 318);
-
this.m_LoadButton.Name = "m_LoadButton";
-
this.m_LoadButton.Size = new System.Drawing.Size(75, 23);
-
this.m_LoadButton.TabIndex = 1;
-
this.m_LoadButton.Text = "Load image";
-
this.m_LoadButton.UseVisualStyleBackColor = true;
-
this.m_LoadButton.Click += new System.EventHandler(this.m_LoadButton_Click);
-
//
-
// m_OpenFileDialog
-
//
-
this.m_OpenFileDialog.FileName = "openFileDialog1";
-
//
-
// panel1
-
//
-
this.panel1.AllowDrop = true;
-
this.panel1.BackgroundImage = global::CenterPictureBox.Properties.Resources.icon;
-
this.panel1.Location = new System.Drawing.Point(23, 135);
-
this.panel1.Name = "panel1";
-
this.panel1.Size = new System.Drawing.Size(60, 60);
-
this.panel1.TabIndex = 4;
-
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
-
this.panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.panel1_DragDrop);
-
this.panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.panel1_DragEnter);
-
//
-
// panel2
-
//
-
this.panel2.AllowDrop = true;
-
this.panel2.BackgroundImage = global::CenterPictureBox.Properties.Resources.darktower;
-
this.panel2.Controls.Add(this.panel3);
-
this.panel2.Location = new System.Drawing.Point(429, 12);
-
this.panel2.Name = "panel2";
-
this.panel2.Size = new System.Drawing.Size(320, 480);
-
this.panel2.TabIndex = 3;
-
this.panel2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel2_MouseDown);
-
this.panel2.DragDrop += new System.Windows.Forms.DragEventHandler(this.panel2_DragDrop);
-
this.panel2.DragEnter += new System.Windows.Forms.DragEventHandler(this.panel2_DragEnter);
-
//
-
// panel3
-
//
-
this.panel3.AllowDrop = true;
-
this.panel3.BackColor = System.Drawing.Color.Transparent;
-
this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
-
this.panel3.Location = new System.Drawing.Point(26, 21);
-
this.panel3.Name = "panel3";
-
this.panel3.Size = new System.Drawing.Size(60, 60);
-
this.panel3.TabIndex = 0;
-
this.panel3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel3_MouseDown);
-
this.panel3.DragDrop += new System.Windows.Forms.DragEventHandler(this.panel3_DragDrop);
-
this.panel3.DragEnter += new System.Windows.Forms.DragEventHandler(this.panel3_DragEnter);
-
//
-
// Form1
-
//
-
this.AllowDrop = true;
-
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
-
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-
this.ClientSize = new System.Drawing.Size(761, 525);
-
this.Controls.Add(this.panel1);
-
this.Controls.Add(this.panel2);
-
this.Controls.Add(this.m_LoadButton);
-
this.Controls.Add(this.m_PaintPanel);
-
this.Name = "Form1";
-
this.Text = "Form1";
-
this.Load += new System.EventHandler(this.Form1_Load);
-
this.panel2.ResumeLayout(false);
-
this.ResumeLayout(false);
-
-
}
-
-
#endregion
-
-
private System.Windows.Forms.Panel m_PaintPanel;
-
private System.Windows.Forms.Button m_LoadButton;
-
private System.Windows.Forms.OpenFileDialog m_OpenFileDialog;
-
-
private void m_PaintPanel_Paint_1(object sender, PaintEventArgs e)
-
{
-
-
}
-
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
-
}
-
-
-
-
-
-
-
-
-
-
-
private void panel2_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
private void panel2_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
}
-
-
private void panel2_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
-
private void m_PaintPanel_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
-
private void m_PaintPanel_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
private void m_PaintPanel_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
}
-
-
private void panel3_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
private void panel3_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
}
-
-
private void panel3_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
-
private void panel1_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
-
private void panel1_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
private void panel1_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
}
-
}
-
}
-
I have added a panel and a open dialog that paints an image in the panel but I cannot drag the image to any other panels.
With what I have here I can drag and drop in the same form.
I cannot drag from the image opened in panel1 from the load button. -
-
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace OpeninPanel
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private Bitmap m_Bitmap = null;
-
-
private void m_LoadButton_Click( object sender, EventArgs e )
-
{
-
if( m_OpenFileDialog.ShowDialog( this ) == DialogResult.OK )
-
{
-
m_Bitmap = new Bitmap( m_OpenFileDialog.FileName );
-
-
m_PaintPanel.SuspendLayout();
-
m_PaintPanel.Controls.Clear();
-
-
Panel panel = new Panel();
-
//int left = 0, top = 0;
-
//if( m_Bitmap.Width < m_PaintPanel.Width )
-
//{
-
// left = ( m_PaintPanel.Width - m_Bitmap.Width ) / 2;
-
// }
-
// if( m_Bitmap.Height < m_PaintPanel.Height )
-
// {
-
// top = (m_PaintPanel.Height - m_Bitmap.Height) / 2;
-
// }
-
panel.Size = m_Bitmap.Size;
-
// panel.Location = new Point( left, top );
-
panel.Paint += new System.Windows.Forms.PaintEventHandler( this.m_PaintPanel_Paint );
-
m_PaintPanel.Controls.Add( panel );
-
-
m_PaintPanel.ResumeLayout();
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
}
-
-
private void m_PaintPanel_Paint( object sender, PaintEventArgs e )
-
{
-
if( m_Bitmap != null )
-
{
-
e.Graphics.DrawImageUnscaled( m_Bitmap, 0, 0 );
-
}
-
}
-
-
/// <summary>
-
/// Required designer variable.
-
/// </summary>
-
private System.ComponentModel.IContainer components = null;
-
-
/// <summary>
-
/// Clean up any resources being used.
-
/// </summary>
-
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
-
-
-
#region Windows Form Designer generated code
-
-
/// <summary>
-
/// Required method for Designer support - do not modify
-
/// the contents of this method with the code editor.
-
/// </summary>
-
private void InitializeComponent()
-
{
-
this.m_PaintPanel = new System.Windows.Forms.Panel();
-
this.m_LoadButton = new System.Windows.Forms.Button();
-
this.m_OpenFileDialog = new System.Windows.Forms.OpenFileDialog();
-
this.panel1 = new System.Windows.Forms.Panel();
-
this.panel2 = new System.Windows.Forms.Panel();
-
this.panel3 = new System.Windows.Forms.Panel();
-
this.panel2.SuspendLayout();
-
this.SuspendLayout();
-
//
-
// m_PaintPanel
-
//
-
this.m_PaintPanel.AllowDrop = true;
-
this.m_PaintPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-
| System.Windows.Forms.AnchorStyles.Left)
-
| System.Windows.Forms.AnchorStyles.Right)));
-
this.m_PaintPanel.BackColor = System.Drawing.Color.Transparent;
-
this.m_PaintPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
-
this.m_PaintPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
-
this.m_PaintPanel.Location = new System.Drawing.Point(273, 107);
-
this.m_PaintPanel.Name = "m_PaintPanel";
-
this.m_PaintPanel.Size = new System.Drawing.Size(121, 190);
-
this.m_PaintPanel.TabIndex = 0;
-
this.m_PaintPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.m_PaintPanel_MouseDown);
-
this.m_PaintPanel.DragDrop += new System.Windows.Forms.DragEventHandler(this.m_PaintPanel_DragDrop);
-
this.m_PaintPanel.DragEnter += new System.Windows.Forms.DragEventHandler(this.m_PaintPanel_DragEnter);
-
this.m_PaintPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.m_PaintPanel_Paint_1);
-
//
-
// m_LoadButton
-
//
-
this.m_LoadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
-
this.m_LoadButton.Location = new System.Drawing.Point(299, 318);
-
this.m_LoadButton.Name = "m_LoadButton";
-
this.m_LoadButton.Size = new System.Drawing.Size(75, 23);
-
this.m_LoadButton.TabIndex = 1;
-
this.m_LoadButton.Text = "Load image";
-
this.m_LoadButton.UseVisualStyleBackColor = true;
-
this.m_LoadButton.Click += new System.EventHandler(this.m_LoadButton_Click);
-
//
-
// m_OpenFileDialog
-
//
-
this.m_OpenFileDialog.FileName = "openFileDialog1";
-
//
-
// panel1
-
//
-
this.panel1.AllowDrop = true;
-
this.panel1.BackgroundImage = global::CenterPictureBox.Properties.Resources.icon;
-
this.panel1.Location = new System.Drawing.Point(23, 135);
-
this.panel1.Name = "panel1";
-
this.panel1.Size = new System.Drawing.Size(60, 60);
-
this.panel1.TabIndex = 4;
-
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
-
this.panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.panel1_DragDrop);
-
this.panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.panel1_DragEnter);
-
//
-
// panel2
-
//
-
this.panel2.AllowDrop = true;
-
this.panel2.BackgroundImage = global::CenterPictureBox.Properties.Resources.darktower;
-
this.panel2.Controls.Add(this.panel3);
-
this.panel2.Location = new System.Drawing.Point(429, 12);
-
this.panel2.Name = "panel2";
-
this.panel2.Size = new System.Drawing.Size(320, 480);
-
this.panel2.TabIndex = 3;
-
this.panel2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel2_MouseDown);
-
this.panel2.DragDrop += new System.Windows.Forms.DragEventHandler(this.panel2_DragDrop);
-
this.panel2.DragEnter += new System.Windows.Forms.DragEventHandler(this.panel2_DragEnter);
-
//
-
// panel3
-
//
-
this.panel3.AllowDrop = true;
-
this.panel3.BackColor = System.Drawing.Color.Transparent;
-
this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
-
this.panel3.Location = new System.Drawing.Point(26, 21);
-
this.panel3.Name = "panel3";
-
this.panel3.Size = new System.Drawing.Size(60, 60);
-
this.panel3.TabIndex = 0;
-
this.panel3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel3_MouseDown);
-
this.panel3.DragDrop += new System.Windows.Forms.DragEventHandler(this.panel3_DragDrop);
-
this.panel3.DragEnter += new System.Windows.Forms.DragEventHandler(this.panel3_DragEnter);
-
//
-
// Form1
-
//
-
this.AllowDrop = true;
-
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
-
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-
this.ClientSize = new System.Drawing.Size(761, 525);
-
this.Controls.Add(this.panel1);
-
this.Controls.Add(this.panel2);
-
this.Controls.Add(this.m_LoadButton);
-
this.Controls.Add(this.m_PaintPanel);
-
this.Name = "Form1";
-
this.Text = "Form1";
-
this.Load += new System.EventHandler(this.Form1_Load);
-
this.panel2.ResumeLayout(false);
-
this.ResumeLayout(false);
-
-
}
-
-
#endregion
-
-
private System.Windows.Forms.Panel m_PaintPanel;
-
private System.Windows.Forms.Button m_LoadButton;
-
private System.Windows.Forms.OpenFileDialog m_OpenFileDialog;
-
-
private void m_PaintPanel_Paint_1(object sender, PaintEventArgs e)
-
{
-
-
}
-
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
-
}
-
-
-
-
-
-
-
-
-
-
-
private void panel2_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
private void panel2_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
}
-
-
private void panel2_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
-
private void m_PaintPanel_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
-
private void m_PaintPanel_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
private void m_PaintPanel_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
}
-
-
private void panel3_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
private void panel3_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
}
-
-
private void panel3_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
-
private void panel1_MouseDown(object sender, MouseEventArgs e)
-
{
-
//we will pass the data that user wants to drag DoDragDrop method is used for holding data
-
//DoDragDrop accepts two paramete first paramter is data(image,file,text etc) and second paramter
-
//specify either user wants to copy the data or move data
-
-
Panel source = (Panel)sender;
-
DoDragDrop(source.BackgroundImage, DragDropEffects.Copy);
-
}
-
-
private void panel1_DragDrop(object sender, DragEventArgs e)
-
{
-
//target control will accept data here
-
Panel destination = (Panel)sender;
-
destination.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
private void panel1_DragEnter(object sender, DragEventArgs e)
-
{
-
//As we are interested in Image data only we will check this as follows
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
e.Effect = DragDropEffects.Copy;
-
}
-
else
-
{
-
e.Effect = DragDropEffects.None;
-
}
-
}
-
}
-
}
-
hi.
I have never tried dragging and dropping with applications
Found 2 links which should help u out, one is in vb, hope u transalet that to c# if it is so
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.allowdrop(VS.80).aspx
http://www.ondotnet.com/pub/a/dotnet/2002/11/11/dragdrop.htm
and please keep ure comments tidy
Plater 7,872
Recognized Expert Expert
If you are dragging a file, it will NOT show up as bitmap data.
You should debug and look at what DataTypes are sent when you drag and drop.
Thanks for your responses I have it all sorted out now.
Here is the solution for anyone else looking to do this. Drag and drop images from outside the form into panels. -
-
private void OpenFile(string ImageFile)
-
{
-
Bitmap bmp;
-
-
try
-
{
-
// Load bitmap file
-
bmp = (Bitmap)Bitmap.FromFile(ImageFile, false);
-
-
if (bmp != null)
-
{
-
// Keep bitmap in class member
-
m_Bitmap = (Bitmap)bmp.Clone();
-
-
this.AutoScroll = true;
-
this.AutoScrollMinSize = new Size(
-
m_Bitmap.Width,
-
m_Bitmap.Height);
-
-
Invalidate();
-
}
-
}
-
catch (Exception ex)
-
{
-
MessageBox.Show(this, ex.Message, "Error loading from file");
-
}
-
-
}
-
-
-------------------------------------------------------------------------------------------------------------------
-
-
-
-
private void panel6_DragDrop(object sender, DragEventArgs e)
-
{
-
try
-
{
-
if (e.Data.GetDataPresent(DataFormats.FileDrop))
-
{
-
Array a = (Array)e.Data.GetData(DataFormats.FileDrop);
-
if (a != null)
-
{
-
string s = a.GetValue(0).ToString();
-
this.OpenFile(s);
-
this.panel6.BackgroundImage = m_Bitmap;
-
}
-
}
-
else
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
{
-
Panel dich = (Panel)sender;
-
dich.BackgroundImage = (Bitmap)e.Data.GetData(typeof(Bitmap));
-
}
-
-
}
-
catch (Exception ex)
-
{
-
Trace.WriteLine("Error in DragDrop function: " + ex.Message);
-
}
-
}
-
-
-
private void panel6_DragEnter(object sender, DragEventArgs e)
-
{
-
// If file is dragged, show cursor "Drop allowed"
-
-
if (e.Data.GetDataPresent(DataFormats.FileDrop))
-
e.Effect = DragDropEffects.Copy;
-
else
-
if (e.Data.GetDataPresent(typeof(Bitmap)))
-
e.Effect = DragDropEffects.Move;
-
else
-
e.Effect = DragDropEffects.None;
-
-
-
-
}
-
-
private void panel6_MouseDown(object sender, MouseEventArgs e)
-
{
-
Panel nguon = (Panel)sender;
-
DoDragDrop(nguon.BackgroundImage, DragDropEffects.Move);
-
}
-
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: SamSpade |
last post by:
There seems to be two ways to put things on the clipboard ( I don't mean
different formats): SetClipboardData and OleSetClipboard
If I want to get data off the clipboard do I care how it was put...
|
by: Ajay Krishnan Thampi |
last post by:
I have a slight problem implementing 'drag and drop' from a datagrid
to a tree-view. I have pasted my code below. Someone please advice me
on what to do...pretty blur right now.
==code==
...
|
by: zav |
last post by:
Hi all i`m having a small problem with windows forms, i`m attempting to
provide the following functionality to a form.
Ability to drag and drop another form onto a form and then to dock this...
|
by: rob |
last post by:
I'm trying to create a UI which allows to move objects. I
would like to give reall drag and drop feature.. I do not
want to give fake drag and drop.
When the user selects it should create a...
|
by: Kevin L |
last post by:
I have a Panel control that I currently allow the user to drag and
reposition on a form at runtime.
This Panel control contains a Label control.
I would like to allow the user to drag the PANEL...
| |
by: petermichaux |
last post by:
Hi,
I am trying to put together the last major pieces of my project's
puzzle. This is more website/client-side architecture than
JavaScript syntax but I hope this is a good place to ask. I'm a...
|
by: JeffDotNet |
last post by:
I wrote a small data processing application that writes a summary of
several hundred files. I use drag and drop on a panel (Panel1) to grab
the absolute path to each of these files. Then I begin...
|
by: Blkpower |
last post by:
Hi to all,
I'm writing a windows form application that has a panel with some
labels in it.
I need to let the user move these labels with drag and drop inside the
panel. How can I do it?
I now...
|
by: jawilson |
last post by:
Hello,
I am trying to use drag-n-drop for a listview control in my program. I
created a new listview control class (just call it MyListView) that
inherits from ListView, and creates a few new...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |