DesktopLocation vs Control.MousePosition vs e.Location (where e is MouseEventArgs)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ducttape
    New Member
    • May 2009
    • 15

    DesktopLocation vs Control.MousePosition vs e.Location (where e is MouseEventArgs)

    Hello

    I'm busy working with an MDI parent and child forms. I've found that there is a discrepancy between the locations returned by DesktopLocation , Control.MousePo sition and MouseEventArgs e.Location, but I can't work out why or what exactly the discrepancy is.

    My forms are all custom without title bars and thus I've had to create my own moving methods, etc. This is obviously related to the location of the mouse pointer. My mouse events are generated by clicking on the child forms. It seems that MouseEventArgs returns a location relative to the form that was clicked. Seeing as I need locations in relation to the parent form as a whole, I've tried instead to use Control.MousePo sition. Unfortunately I've found that the locations of Control.MousePo sition and the DesktopLocation of the form seems to be different (ie a click in the top left corner of the form is not the same).

    Does anyone know from where this discrepancy arises so I can correct for it, or of a better way to get the mouse position?

    Thanks
  • cloud255
    Recognized Expert Contributor
    • Jun 2008
    • 427

    #2
    Have a look at the PointToClient method. It creates a point relative to the parent of the control, in this case the MDIContainer.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      The mouseeventargs is for the position relative to the control that triggered the event.
      Forms.DesktopLo cation says the following: "Gets or sets the location of the form on the Windows desktop. Desktop coordinates are based on the working area of the screen, which excludes the taskbar. The coordinate system of the desktop is pixel based. If your application is running on a multimonitor system, the coordinates of the form are the coordinates for the combined desktop."
      So it sounds like its just telling you where the form is located on the screen.

      Control.MousePo sition gives the cursor position relative to desktop. (I just verified, the top-left corner of my screen was 0,0 and etc)

      Comment

      Working...