473,804 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mouse coordinates relative to a control

Hi,
I'm trying to drag and drop onto a Panel on my form. The panel is inside
a groupBox, which of course is inside my form.

When dropping the item onto my Panel, I want it to appear at that point
on the Panel, and therefore need the mouse coordinates relative to the
Panel and not the form itself. Something like:

private void myPanel_DragDro p(object sender, DragEventArgs e)
{
tempPoint = //insert location finding code here...
draggedLabe.Tex t = (string) e.Data.GetData( DataFormats.Tex t);
draggedLabel.Lo cation = tempPoint;
myPanel.Control s.Add(draggedLa bel);
}

I've tried doing this by taking the DragEventArgs mouse coords and
subtracting the panel's location and the groupBox's location, but still
no dice.

I've also tried using:
(Point) (visPanel.Locat ion + (Size) (PointToScreen( Point.Empty) - (Size)
Location));

Which should give the mouse coords relative to my control, but it
doesn't refresh for some reason.

Any simple solutions? I've googled for ages...

Cheers,
-robin

reverse my username to email me.
Nov 15 '05 #1
2 21465
n!
> When dropping the item onto my Panel, I want it to appear at that point
on the Panel, and therefore need the mouse coordinates relative to the
Panel and not the form itself. Something like:


Do you have a reference to the form which is the source of the Drag
operation? I assume that the 'sender' parameter you are receiving is one?

private void myPanel_DragDro p( object sender, DrawEventArgs e )
{
Control source = ( Control )sender;

// Obtain screen location of drag event...
Point screen = source.PointToS creen( new Point( e.X, e.Y ) );

// And convert it to our local coordinate system...
Point local = PointToClient( screen );
}

Which should leave you with a location local to your panel inside the
'local' variable.

n!
Nov 15 '05 #2
n! wrote:
Do you have a reference to the form which is the source of the Drag
operation? I assume that the 'sender' parameter you are receiving is one?

private void myPanel_DragDro p( object sender, DrawEventArgs e )
{
Control source = ( Control )sender;

// Obtain screen location of drag event...
Point screen = source.PointToS creen( new Point( e.X, e.Y ) );

// And convert it to our local coordinate system...
Point local = PointToClient( screen );
}

Which should leave you with a location local to your panel inside the
'local' variable.


Hi,
You almost got it, but still lead me in the right direction. All I
needed to do was:
Point local = myPanel.PointTo Client( new Point(e.X,e.Y)) ;

Thanks so much!
-robin
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
474
by: TB | last post by:
Howdy... I have an asp.net web form with an ImageButton control on the form. When clicked, the ImageButton's click event handler is supposed to pass X and Y coordinates of the mouse click's location on the PAGE. I know that I can see the X, Y coords for the click event relative to the ImageButton control, but this does no good for my particular application. What I am trying to do is display a calendar user control at the exact...
10
18089
by: Danny | last post by:
How can I get the coordinates of the mouse cursor in Mozilla browsers as well as Opera and IE6? I'm struggling to understand how to capture mouse movement events with Mozilla/Netscape/Firefox and I've Googled so much my brain hurts. http://www.ghpkendal.co.uk/TestPages/Test.htm Move your cursor over the yellow area and you should see the mouse coordinates echoed above.
4
14730
by: Jay | last post by:
Hi, How can I capture mouse position on Image? I found number of script capturing mouse position of the page. But I could not find anything based on image. What I want to find out is X Y coordinates of mouse position. based on left of the top of my image is 0 0 (X Y coordinates) otherwise, I need to find out position of my image so I can calculate.
2
4400
by: Robert Chan | last post by:
I have a form that is 2000x700 it is meant to be run across two monitors I want to get the mouse position relative to the form not to the screen is there any kind of way to reference the forms position on the screen, to tell where the mouse is in relation to the form and so that I can know which part of a panel someone clicked on. thanks in advance --rob
8
2787
by: Tom | last post by:
Hi I am having problems working out if the mouse pointer is within the control bounds within the OnMouseMove method: Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs) Debug.WriteLine(Me.Bounds.Contains(e.X, e.Y)) End Sub
2
19595
by: quickcur | last post by:
Hi, I have html like this: <div id="myCanvas" style="border:10px, black;position:relative;height:250px;width:100%;"> <img id="p" src="p.jpg"> </div> When user click the mosue, I would like 1. Test if the mouse location is on top of the image
4
11782
by: Johnny Jensen | last post by:
Hello Group In the old days i'ev created a VB6 appl. that was able to obtain the underlaying control under the mouse pointer. I would very much like to do that in a C# application. I'll use VS2005 and .Net 2.0 I'll know of the solution to code each control for the mouse over event, but I cant use that i this case. Any one outthere with som examples?
1
4765
by: Randy | last post by:
I'm struggling with identifying whether a user has clicked on the left or right arrows within the MonthCalendar controls. I had a good suggestion to trap the mouse coordinates that the user clicks to determine if they have clicked within the region where the arrow exists. My problem is that my form is not maximized and therefore the control can exist almost anywhere on the user's screen. I thought about forcing the form to a fixed...
4
2900
by: =?Utf-8?B?Unlhbg==?= | last post by:
I have a winform containing a scrollable panel and a groupbox inside the panel. There is a button inside the groupbox. When that button is clicked; how do I capture and display the X and Y coordinates in a messagebox?
0
9715
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
9595
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,...
1
10354
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
9175
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
6867
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();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
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.