473,473 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

15 New Member
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.MousePosition 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.MousePosition. Unfortunately I've found that the locations of Control.MousePosition 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
Aug 27 '09 #1
2 5411
cloud255
427 Recognized Expert Contributor
Have a look at the PointToClient method. It creates a point relative to the parent of the control, in this case the MDIContainer.
Aug 27 '09 #2
Plater
7,872 Recognized Expert Expert
The mouseeventargs is for the position relative to the control that triggered the event.
Forms.DesktopLocation 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.MousePosition gives the cursor position relative to desktop. (I just verified, the top-left corner of my screen was 0,0 and etc)
Aug 27 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. ...
3
by: Charles Law | last post by:
Sorry for reposting this question, but I did not get a single answer last time, and I'm sure you guys must have some thoughts on the matter. I have a user control which can be dragged and dropped...
1
by: siliconpi | last post by:
I'm looking for the simplest and cleanest way of having 10 buttons on a form, on which if I move my mouse over, a label's text changes as specified. I'm using Visual Basic .NET and I'm not too...
6
by: Jack | last post by:
Hello, I've noticed through searching this group's previous posts that one can get the item the mouse is over in a listview control but I did not see how to get the subitem the mouse is over. Is...
7
by: iwdu15 | last post by:
hi, im trying to egt a picturebox to follow the mousecursor around in a certain area, but the picturebox isnt where the mouse is...how can i get the picturebox to be where the mouse cursor is?...
2
by: bretth | last post by:
In a VB.Net Windows Forms application, I have a user control that handles mouse events. Another section of code programmatically adds a label to the control. I would like label to ignore all...
0
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers......
2
by: Steve Richter | last post by:
I am using ShowDialog to show a popup form and want to position the popup relative to the control on the form the popup is pertinent to. For this, I am using FormStartPosition.Manual to set the...
14
by: akshaycjoshi | last post by:
The code below shows the same values for both private void mainform_Move(object sender, EventArgs e) { lbllocation.Text = "location" + this.Location.ToString(); ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.