Hi,
The following code below displays the mouse coordinates alongside the cursor.
My problem is this-- I my WinForm displays an XY coordinate graph. I need the
origin to display (0, 0) i.e "my coordinates" which which appear in screen coords
as (210, 210).
What is the best way to accomplish this?
I tried Transform but I can't seem to pass information between a Rect to a Region, or somehow get the Transformed coordinates to change what the mouse is doing.
I would like any way to do this. It doesn't have to use Transform.
Thanks a lot in advance. Code is below.
////////////////////////////////////////////////////////////////////
protected override void OnMouseMove(MouseEventArgs e)
{
// TODO: Add Form1.OnMouseMove implementation
base.OnMouseMove (e)
mousePoints = new Point(e.X, e.Y);
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
// TODO: Add Form1.OnPaint implementation
base.OnPaint (e);
Point screen = PointToScreen(mousePoints);
string location = screen.ToString();
e.Graphics.DrawString(location,
e.Graphics.DrawString(" " + (screen), new Font("Arial", 10, FontStyle.Bold),
SystemBrushes.ControlText,(PointF)mousePoints);
}
////////////////////////////////////////////////////////////////
Want Mouse Coordinates To Be "Translated" To My Coordinates
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Matt Speller14 pointsPosted Jan 3, 2006, 11:20 PM EST
string location; Point point; protected override void OnMouseMove(MouseEventArgs e) { // TODO: Add Form1.OnMouseMove implementation base.OnMouseMove(e); string location = this.PointToClient(new Point( e.X, e.Y)).ToString(); point = new Point(e.X, e.Y); Invalidate(); } protected override void OnPaint(PaintEventArgs e) { // TODO: Add Form1.OnPaint implementation base.OnPaint (e); e.Graphics.DrawString(location + " " + (point), new Font("Arial", 10, FontStyle.Bold), SystemBrushes.ControlText,(PointF)point); }