MDI Child Form Drag Without Toolbar
-
Hello, I've been working on an MDI .NET project and am having a problem with my MDI children. There are 6 children that have no toolbars, some are resizeable. I want the user to be able to click anywhere on the child forms (except for controls) and drag that child around anywhere inside the MDI parent. My problem is that I can't seem to get them to drag properly or look attractive while dragging. The mouse cursor will become offset during the drag and move ahead of the form, or there are bad trailing effects following the forms that won't go away until the user releases the mouse. I've been unable to find any information that would help with effecient and attractive full-form dragging. Basically I want to simulate dragging the form toolbar while clicking anywhere on the form. Any help or direction to an article/post would be very appreciated. Cyric
-
Hello, I've been working on an MDI .NET project and am having a problem with my MDI children. There are 6 children that have no toolbars, some are resizeable. I want the user to be able to click anywhere on the child forms (except for controls) and drag that child around anywhere inside the MDI parent. My problem is that I can't seem to get them to drag properly or look attractive while dragging. The mouse cursor will become offset during the drag and move ahead of the form, or there are bad trailing effects following the forms that won't go away until the user releases the mouse. I've been unable to find any information that would help with effecient and attractive full-form dragging. Basically I want to simulate dragging the form toolbar while clicking anywhere on the form. Any help or direction to an article/post would be very appreciated. Cyric
I'm not sure how you're doing it now, but basically set a flag in the
MouseDownm
event handler (or better, overrideOnMouseDown
, which also is better for the other events I'll mention - just don't forget to callbase.On_EventName_
). In theMouseMove
handler move your form only if the flag is set. Finally, in theMouseUp
handler reset the flag. While moving the form, you have a couple of choices. You can simply set theLocation
property but that is what is most likely causing your lag (and related problems). There's quite a bit that happens in the implementation for setting theLocation
property. In theMouseDown
handler, it might be better to callSuspendLayout
and then callResumeLayout
in theMouseUp
handler. I haven't tried this so I don't know how well this will work, and it may not even display the form while dragging. You might instead consider P/Invoking theSetWindowPos
API, which you can find more information about in the Platform SDK documentation in the MSDN Library[^]. This should result in much faster code and should eliminate that lag you're experiencing.Microsoft MVP, Visual C# My Articles