Hello all,
I'm trying to create an application where a user clicks on one of the values in a dataviewgrid, which will generate a panel with two labels on it filled with data from the dataviewgrid. In the same movement the user should drag and drop that panel on a picture.
Generating the panel is not the problem, that works fine. However, when the panel has been created I should trigger the MouseMove-event to be able to drag that panel, but that doesn't work for me.
I'm trying to do it in the same MouseDown-action. So when the user clicks on the info the panel pops up and in the same movement the panel should be dropped onto the picturebox.
If the user releases the mousebutton on top of the grid the panel should be removed because it can only be dropped on the picturebox.
Can anyone point me in the right direction?
Thanks
I'm trying to create an application where a user clicks on one of the values in a dataviewgrid, which will generate a panel with two labels on it filled with data from the dataviewgrid. In the same movement the user should drag and drop that panel on a picture.
Generating the panel is not the problem, that works fine. However, when the panel has been created I should trigger the MouseMove-event to be able to drag that panel, but that doesn't work for me.
I'm trying to do it in the same MouseDown-action. So when the user clicks on the info the panel pops up and in the same movement the panel should be dropped onto the picturebox.
If the user releases the mousebutton on top of the grid the panel should be removed because it can only be dropped on the picturebox.
Can anyone point me in the right direction?
Thanks
Code:
private void grdInfo_MouseDown(object sender, MouseEventArgs e)
{
// GET THE MOUSE COORDINATES
var MouseCoordinates = this.PointToClient(Cursor.Position);
if (e.Button == MouseButtons.Left)
{
// CREATE A PANEL
Panel panTemp = new Panel();
this.Controls.Add(panTemp);
panTemp.Name = "panTemp";
panTemp.BackColor = Color.Orange;
panTemp.Width = 100;
panTemp.Height = 35;
panTemp.Location = new Point(MouseCoordinates.X-69, MouseCoordinates.Y-26);
panTemp.Enabled = true;
panTemp.BringToFront();
panTemp.MouseDown += Panel_MouseDown;
}
}
private void panPitch_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void panPitch_DragDrop(object sender, DragEventArgs e)
{
((Panel)e.Data.GetData(typeof(Panel))).Parent = (Panel)sender;
}
private void grdInfo_MouseUp(object sender, MouseEventArgs e)
{
// DESTROY THE PANEL
var panel = this.Controls["panTemp"];
panel.Dispose();
}