Click here to Skip to main content
15,889,871 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi everybody!

when i worked with a label location i faced with a problem, i was working with these frames : x = vt + x0 and y = 1/2 * a * t + v0 * t + y0
that in it the x or y are most of the time less than 1 (e.g 0.76) because the T that i used was so small . i was using these frames to change the location of a label but it doesn't work because i should write a int at this code : label1.Location = new point (intA , intB);

but the x , y was a double or a decimal . how can i solve this problem , i mean is there any other code to change the location of a label but gets a double or a decimal or other way to solve this?

I asked this question before and I understood there is no what to use a point as a decimal.
So I want it because I wanted to make a "Motion Simolation" Project. I am sure you've seen these project in some tv games or so.. How they write them with which kind of code??

thanks
doostl ;)
Posted
Updated 13-Jan-12 1:48am
v5

Add some scaling if the data range does not match the screen range.
 
Share this answer
 
No, a Point is always int.
A PointF[^] on the other hand...

The other alternative is to cast the double to an int - the fractional part won't make a lot of difference to the label location anyway.
 
Share this answer
 
Moving a label by less than a pixel is rather pointless. As Philippe suggests, you should scale the numbers first so that the position is meaningful and the user can see that it has moved.

To actually perform the cast you do
label.Location = new Point((int)x, (int)y);
// or
label.Top = (int)y; label.Left = (int)x;


But when x and y are around 0 this will result in a non moving label.
 
Share this answer
 

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