views:

45

answers:

1

I have a form with a panel docked in it. I then dynamically create 15 panels (named: panel_n) and 15 pictureboxes (named: picturebox_n) on the primary panel (named ContainerPanel).

When dragging the any picturebox over a panel (panel_n) created using the relevant mouse events. I would like to get the panel's name that the picture box was dragged over. The mouse cursor seems to be captured.

I have tried creating a IMessageFilter interface, but there are still no events that trigger when dragging one of the pictureboxes over any one of the panels.

The ClientRectangle.IntersectsWith function also does not work as the co-ords are always 0,0.

All I need is the panel name where the picturebox was dragged over (preferably on the mouseup event)

A: 

If you give the pictureboxes an OnMouseDown event that says something like this:

(sender as PictureBox).DoDragDrop(sender, DragDropEffects.Copy);

Then you can set the panels' AllowDrop property to true, and in their OnDragDrop event, you can get their name like this:

string myName = (sender as Panel).Name;

Edit: Also, you need to give the panels an OnDragEnter event like this:

e.Effect = DragDropEffects.Copy;

Of course, you can change Copy to Move or Link or whatever is appropriate for what you're doing. It just changes the mouse-pointer icon that's used.

Blorgbeard
Thanks. I cant seem to get your suggestion workingI have added the following to the Pic control that I create on the mousedown event.pb.DoDragDrop(sender, DragDropEffects.Copy);I have also added the following event to my panelsctl.DragDrop += new DragEventHandler(ctl_DragDrop);Here is the event functionprivate void ctl_DragDrop(object sender, DragEventArgs e){ string myName = (sender as Panel).Name; MessageBox.Show("Dragged to Panel:" + myName);} // private void ctl_DragDrop(object sender, DragEventArgs e)When I drag any pciturebox, it shows a "no entry" mouse cursor.
Thomas
I also added the PanelBeat[i].AllowDrop = true; on my dynamically generated panels
Thomas
@Thomas sorry, missed a bit of code. Edited my answer. Btw, next time you should edit your question to add stuff like the above comment - much easier to read code when it's formatted :)
Blorgbeard
Thanks. Will update my code and let you know. (Will change my follow on comments as instructed)
Thomas
It worked. Thanks
Thomas