G
Guest
I've been trying to perform a drag and drop operation from a PictureBox
control in a standard C# form (with a FixedToolWindow border) to another
standard C# form, but cannot get it to work properly.
In the FixedToolWindow, I have the following code:
myClass c = new myClass(); // contains public variable m_MouseIsDown
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (! (pictureBox1.Image == null))
c.m_MouseIsDown = true;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (c.m_MouseIsDown)
pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
}
In the second form, I have the DropAllow property enabled and have the
following code in it:
myClass c = new myClass(); // contains public variable m_MouseIsDown
private int picboxCount;
private PictureBox picbox;
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (c.m_MouseIsDown)
{
int i = picboxCount;
picbox = new PictureBox();
this.Controls.Add(picbox);
picbox.Name = "pictureBox" + i.ToString();
picbox.BorderStyle = BorderStyle.FixedSingle;
picbox.Size = new Size(24, 24);
picbox.Image = (Image)e.Data.GetDataPresent(DataFormats.Bitmap);
picbox.Location = this.PointToClient(new Point(e.X - 12, e.Y -
12));
picboxCount++;
c.m_MouseIsDown = false;
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
One problem I've encountered is in the statement
picbox.Image = (Image)e.Data.GetDataPresent(DataFormats.Bitmap);
as I get a compilation error stating that it cannot convert from type 'bool'
to 'System.Drawing.Image'. Commenting it out and hardcoding a value for the
image, I still can't get the drag and drop operation to work.
Any help would be greatly appreciated!
Allen
control in a standard C# form (with a FixedToolWindow border) to another
standard C# form, but cannot get it to work properly.
In the FixedToolWindow, I have the following code:
myClass c = new myClass(); // contains public variable m_MouseIsDown
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (! (pictureBox1.Image == null))
c.m_MouseIsDown = true;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (c.m_MouseIsDown)
pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
}
In the second form, I have the DropAllow property enabled and have the
following code in it:
myClass c = new myClass(); // contains public variable m_MouseIsDown
private int picboxCount;
private PictureBox picbox;
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (c.m_MouseIsDown)
{
int i = picboxCount;
picbox = new PictureBox();
this.Controls.Add(picbox);
picbox.Name = "pictureBox" + i.ToString();
picbox.BorderStyle = BorderStyle.FixedSingle;
picbox.Size = new Size(24, 24);
picbox.Image = (Image)e.Data.GetDataPresent(DataFormats.Bitmap);
picbox.Location = this.PointToClient(new Point(e.X - 12, e.Y -
12));
picboxCount++;
c.m_MouseIsDown = false;
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
One problem I've encountered is in the statement
picbox.Image = (Image)e.Data.GetDataPresent(DataFormats.Bitmap);
as I get a compilation error stating that it cannot convert from type 'bool'
to 'System.Drawing.Image'. Commenting it out and hardcoding a value for the
image, I still can't get the drag and drop operation to work.
Any help would be greatly appreciated!
Allen