I have a program that allows drag and drop into the panel (Picturebox).
How am i to ensure that this picturebox only be dropped into the panel and no where else?
public Form1()
{
InitializeComponent();
string ImagePath = Application.StartupPath + @"\\Model Products v3\";
// string[] Images = new string[] { ImagePath + "FingerprintScanner1Button.jpg", ImagePath + "FingerprintScanner2Button.jpg", ImagePath + "FingerprintScanner3Button.jpg" };
string[] Images = new string[] { ImagePath + "FingerprintScanner1Button.jpg" };
foreach (string img in Images)
{
PictureBox PB = new PictureBox();
PB.Width = PB.Height = 43;
PB.Location = new Point(38, 13);
PB.Image = Image.FromFile(img);
PB.MouseDown += new MouseEventHandler(PB_MouseDown);
PB.MouseHover += new System.EventHandler(PB_MouseHover);
PB.MouseLeave += new System.EventHandler(PB_MouseLeave);
this.Controls.Add(PB);
}
}
void PB_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
x = e.X;
y = e.Y;
PictureBox pictureBox = new PictureBox();
pictureBox.Image = ((PictureBox)sender).Image;
pictureBox.Top = ((PictureBox)sender).Top;
pictureBox.Width = ((PictureBox)sender).Width;
pictureBox.Height = ((PictureBox)sender).Height;
pictureBox.Left = ((PictureBox)sender).Left;
pictureBox.MouseMove += new MouseEventHandler(PictureBox_MouseMove);
pictureBox.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
this.Controls.Add(pictureBox);
pictureBox.BringToFront();
MouseUPDOWN();
}
}
void PB_MouseHover(object sender, System.EventArgs e)
{
mouseLocation = this.PointToClient(Cursor.Position);
pictureBox1.Location = mouseLocation;
pictureBox1.Show();
pictureBox1.BringToFront();
}
void PB_MouseLeave(object sender, System.EventArgs e)
{
pictureBox1.Hide();
}
void PB1_MouseHover(object sender, System.EventArgs e)
{
mouseLocation = this.PointToClient(Cursor.Position);
pictureBox2.Location = mouseLocation;
pictureBox2.Show();
pictureBox2.BringToFront();
}
void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
x = e.X;
y = e.Y;
}
}
void PictureBox_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
((PictureBox)sender).Left += (e.X - x);
((PictureBox)sender).Top += (e.Y - y);
((PictureBox)sender).BringToFront();
}
}
#region MouseAPIs
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public void MouseUPDOWN()
{
mouse_event(MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0);
}
#endregion
}