473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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_DragDrop(object sender, DragEventArgs e)
{
tempPoint = //insert location finding code here...
draggedLabe.Text = (string) e.Data.GetData(DataFormats.Text);
draggedLabel.Location = tempPoint;
myPanel.Controls.Add(draggedLabel);
}

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.Location + (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 21383
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_DragDrop( object sender, DrawEventArgs e )
{
Control source = ( Control )sender;

// Obtain screen location of drag event...
Point screen = source.PointToScreen( 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_DragDrop( object sender, DrawEventArgs e )
{
Control source = ( Control )sender;

// Obtain screen location of drag event...
Point screen = source.PointToScreen( 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.PointToClient( 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
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...
10
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...
4
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...
2
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...
8
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) ...
2
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 ...
4
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...
1
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.