如何使用带小数或双精度的标签位置 [英] how to work with a label location with decimal or double

查看:78
本文介绍了如何使用带小数或双精度的标签位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

当我在标签位置工作时遇到问题,我正在使用以下框架:x = vt + x0和y = 1/2 * a * t + v0 * t + y0
因为我使用的T很小,所以其中的x或y大部分时间都小于1(例如0.76).我正在使用这些框架来更改标签的位置,但是它不起作用,因为我应该在以下代码中写一个int:label1.Location = new point(intA,intB);

但是x,y是双精度或十进制.我该如何解决此问题,我的意思是还有其他代码可以更改标签的位置,但可以使用双精度或十进制或其他方式来解决此问题吗?

我之前问过这个问题,但我知道没有什么可以将点用作小数.
所以我想要它,因为我想创建一个运动模拟"项目.我确定您已经在一些电视游戏中看过这些项目..他们如何用哪种代码编写它们?

谢谢
doostl;)

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 ;)

推荐答案

如果数据范围与屏幕范围不匹配,请添加一些缩放比例.
Add some scaling if the data range does not match the screen range.


否,始终为整数.
PointF [
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.


将标签移动不到一个像素是毫无意义.正如Philippe建议的那样,您应该首先缩放数字,以便该位置有意义,并且用户可以看到它已经移动.

要实际执行演员表,
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;



但是,当x和y大约为0时,这将导致标签不移动.



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


这篇关于如何使用带小数或双精度的标签位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆