Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Mouse position

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doug - 27 Aug 2007 09:16 GMT
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
Kevin Spencer - 27 Aug 2007 11:43 GMT
> 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.

Signature

HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

> Hi
>
[quoted text clipped - 21 lines]
>
> Doug
Alex Meleta - 27 Aug 2007 11:47 GMT
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>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.