Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MDI Child Form Drag Without Toolbar

MDI Child Form Drag Without Toolbar

Scheduled Pinned Locked Moved C#
helpcsharp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cyric74
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • C Cyric74

      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

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      I'm not sure how you're doing it now, but basically set a flag in the MouseDownm event handler (or better, override OnMouseDown, which also is better for the other events I'll mention - just don't forget to call base.On_EventName_). In the MouseMove handler move your form only if the flag is set. Finally, in the MouseUp handler reset the flag. While moving the form, you have a couple of choices. You can simply set the Location 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 the Location property. In the MouseDown handler, it might be better to call SuspendLayout and then call ResumeLayout in the MouseUp 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 the SetWindowPos 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups