views:

117

answers:

2

I have a simple winforms application with a number of controls in it. I want to be able to click and drag from anywhere on the form and move the whole set of stuff around (panning). I have figured out the respositioning bit already. What I still need to figure out is how to tie the click and drag into updating my offsets.

What I have tried so far is adding stuff to the main form's MouseDown, MouseUp and MouseMove events (sort of looks something like what this guy shows) , but they aren't getting called (breakpoints in them don't get hit)

What am I doing wrong?


Edit: I'm not looking for drag and drop as I don't necessarily have anything to be dragged or dropped. What I want would work withe the following spec:

  • create a form with no controls
  • set up an x and y variable that are printed to the form title whenever they update
  • when the user click and drags anywhere on the form, the x and y get updated to reflect the motion of the pointer (click and drag down and to the right will result in x>0 and y>0)


Based on Eric's comment I think I'm hooking up to the events on the wrong control.

Is there a way to (with a setup like controls use) catch all events in one place regardless of what they are supposed to be sent to? Or how about have any otherwise unhanded events get chained up to the parent? In my case I will never care what got the event so this would be what I want to get.

A: 

There are a few tutorials online covering Drag-and-Drop such as this one

the fact that the events arent triggering is not normal. If you have controls over the form, you should hook events of those controls. Another way of doing it would be to have a transparent panel over your whole form which will handle the events

Eric
I'm NOT looking for drag-and-drop. See edit.
BCS
+1  A: 

How do you handle mouse events exactly? If you have panel covering the form, form's mouse events won't be called. Only panel's mouse events would.

Hugo Riley
That might answerer my question right there. The form isn't getting the event because something else is. Eric's comment looks like it might be the way to go.
BCS