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 6520
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.a llowdrop(VS.80) .aspx
http://www.ondotnet.co m/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 there?
What about Drag/Drop; is there more than one way for the source to make data
available
Is it always OLE?
|
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==
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
|
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
form...
Quite a mouthful however a good example of this is within the VS.NET 6 IDE.
Grab your solution explorer panel and drop it outside of the IDE, then
drag/drop it back in and watch it dock.
|
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 border and drag
that border and drop it in the form... (just like moving
icons in windows desktop)
Any idea ?
|
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 clicking on the LABEL
and dragging.
Is there a way to do this?
| |
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 little
stumped with which direction to take and advice would be greatly
appreciated. I think this is a generally interesting problem but I
haven't seen a post this long here before :S
I have developed half of the admin interface for an e-commerce
|
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 analyzing all of
the files. I noticed (on the same machine) that some user profiles
appear to abbreviate the absolute paths to these files thus breaking my
data loading mechanism. Does anyone know how I can programmatically
change this filepath...
|
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 how to drag and drop for example the text contained in a textbox,
but not the whole control.
I read an article called "Fake drag and drop" that works without
dragdrop event and it's not so good.
|
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 properties and methods.
I have set AllowDrop to true, and have all of the Drag* events
written. In addition, the listview is in the detailed view. A simple
explanation of what I want to do is to drag a file from the desktop or
explorer into my...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |