C# Drawing Controls as I drag them

lozina

Lifer
Sep 10, 2001
11,711
8
81
I have a Panel area which has any number of smaller Panels inside of it, and each of these inner panels may have labels and form elements (text box, drop-down, etc..) within them. I want to be able to use drag n drop to re-arrange the order of these inner panels in relation to eachother.

I want it to look like that Windows XP start menu where you have those quick launch icons and frequently used apps icons. See how when you drag n drop them it draws the icon in a sort of faded style as you drag them around? I want to do that with my inner panels, but I can;t even figure out how to draw them as I drag them at all...

See the attached code, what I thought I could do easily is to initiate a drag n drop event using the inner panel itself as the Data, then when the main outer panel receives the drag over event I just pull out the inner panel and change it's location to current mouse cursor. But it doesnt work. What happens is once I start dragging a inner panel it disappears completely and is never redrawn
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I think you're going to have to get deeper into the framework and specialize some paint methods to do this. I will try to do some research when I get home this evening and post some more info.
 

lozina

Lifer
Sep 10, 2001
11,711
8
81
What I tried doing just now was instead of my OuterPanel being extended from Panel I extended from UserControl and instead of trying to change the location of an exisitng control I tried drawing straight to the Graphics (first a simple scenario drawing a string wherever my mouse cursor was). This works when I am using the MouseMove event when not in Drag n Drop mode, but when I try the same code in the DragOver event handler it prints nothing to the screen...

See attached code.

If you took that same code and put it in a MouseMove event handler, it will print "Blah" wherever your cursor is. However as soon as you initiate a Drag n Drop and try this code in the DragOver event handler, nothing happens- no string printed on your cursor as your wave it around. Even if the MouseMove event doing the same code is also still active.

I don't understand why


 

lozina

Lifer
Sep 10, 2001
11,711
8
81
Ok.. Duh! I see what's wrong...

My inner panels have their own mouse event handlers and whether I use them or not when I press and hold left mouse button on one of them and start to drag, the scope of that mouse event remains in that inner panel, never to the outer panel even if I drag the mouse cursor outside the boundaries of that inner panel.

basically I had to register mouse event handlers on the oustide panel for each inner panel, and now I got it working how I expected.

I had thought that when I start dragging and the mouse cursor leaves the boundaries of the inner panel that it would start to be registered as a MouseMove event on the outer panel. nope.