Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I want to store my controls XY position, so I used an object to store that X Y postion values. The object variable is taking that values but when I am assiging that object variable to control location its showing some error like this:

Specified cast is not valid.

this is my code

dim a as object
a = String.Format("Mouse X:{0}, Y:{1}", Control.MousePosition.X, Control.MousePosition.Y)
cb.location = a


here cb is one of control name..

So, please tell me some solution for this
Posted
Updated 1-Nov-10 22:12pm
v2
Comments
qontary 2-Nov-10 4:13am    
String.Format("Mouse X:{0}, Y:{1}", Control.MousePosition.X, Control.MousePosition.Y) is clearly a string. If you want to be able to use the X & Y value you could assign the location property as Point instead.

Hi, try this:
VB
cb.location = New Point(Control.MousePosition.X, Control.MousePosition.Y)
 
Share this answer
 
Comments
sameertm 2-Nov-10 4:18am    
thanks alot
Dalek Dave 2-Nov-10 4:40am    
Good Call.
Rajesh Anuhya 2-Nov-10 5:56am    
Good Answer
Hi,

do like this,
cb.location.X = Control.MousePosition.X;
cb.location.Y = Control.MousePosition.Y;


or,
Point p = new Point(Control.MousePosition.X,Control.MousePosition.Y);
cb.location = p;



Thanks
Arindam D Tewary,
 
Share this answer
 
Comments
sameertm 2-Nov-10 4:22am    
thnks alot Arindam

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900