473,791 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DesktopLocation vs Control.MousePo sition 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.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
Aug 27 '09 #1
2 5460
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.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)
Aug 27 '09 #3

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

Similar topics

0
1925
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.. Chris. code :
3
499
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 onto a form in my application when it is running. I allow it to be clicked and dragged to a new location on the form. However, the user control has a check box on it, and if the user clicks over the checkbox to drag the user control, the check...
1
2720
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 familiar with its intricacies, so I'm getting a bunch of errors on certain scenarios. The code below works fine but breaks if I click on Button1 a few times without moving the program window ----------
6
5039
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 this possible? I intend on replacing an ActiveX grid with a listview control from a VB6 application that I've upgraded to VB .NET. The existing functionlality uses the mouseover event of the grid to display specific information within...
7
7620
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? thanks -- -iwdu15
2
15460
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 events allowing the user control to react to the mouse click. Setting the Enabled property on the label to False comes close, but I don't want the font color to change. Does anyone have an idea how .NET implements the code behind the Enabled...
0
1908
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... then taking that date range and finding dates specifiec between them (in a list of dates) and putting snap marks, so if you slide it near one of them it should snap to that tick, but that part i cant figure out. the rest seems ok so far... here...
2
2172
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 position of the form relative to the desktop. I can calc the location of a control relative to the client rect of a form. But since I am positioning the popup form relative to the desktop, I need to know the DesktopLocation of controls on the...
14
5023
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(); lbldesktoplocation.Text = "location" + this.DesktopLocation.ToString(); } what exactly is the difference ?
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.