Mouse position

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

Hi

I have a form that when a user presses Enter I would like to get the current
mouse position and copy it to the clipboard.

I have tried

private void button1_Click(object sender, EventArgs e)

{

string possi;

possi = (string) Control.MousePosition;

MessageBox.Show(possi.ToString());

}

but this doesnt work and i get the error "Error 1 Cannot convert type
'System.Drawing.Point' to 'string' "



Any help appreciated..



Doug
 
string possi;
possi = (string) Control.MousePosition;

You cannot cast System.Drawing.Point as a string. You can use the
System.Drawing.Point.ToString() method to get a string representation of the
Point, but that's different. It is a method that returns a string.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Hi Doug,
possi = (string) Control.MousePosition;
No direct accordance between Point and string, but you're tring directly
cast these types. Use other approaches, e.g. string.Format("{0},{1}", possi.X,
possi.Y) - with avoind of the exception you can also define appropriate format
of string.
MessageBox.Show(possi.ToString());
the string is already a string. No .ToString() is needed.

Regards, Alex
[TechBlog] http://devkids.blogspot.com



D> possi = (string) Control.MousePosition;
D>
 
Back
Top