如何围绕一个点旋转图片框? [英] How do I rotate a picturebox around a point?
本文介绍了如何围绕一个点旋转图片框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已解决
我正在尝试模拟一个旋转恒星的行星.我目前知道移动图片框的语法 (我将其放在计时器中,因此可以重复执行)
private void rotate_timer(object sender, EventArgs e) {
picturebox1.location = new point (picturebox1.location.x + 1,
picturebox1.location.y + 1);
}
但是我不知道从哪里开始,以便它围绕特定点旋转. 我将如何绕(0,0)旋转?
解决方案
这可能会有所帮助:
float angle = 0;
float rotSpeed = 1;
Point origin = new Point(222, 222); // your origin
int distance = 100; // your distance
private void timer1_Tick(object sender, EventArgs e)
{
angle += rotSpeed;
int x = (int)(origin.X + distance * Math.Sin(angle *Math.PI / 180f));
int y = (int)(origin.Y + distance * Math.Cos(angle *Math.PI / 180f));
yourControl.Location = new Point(x, y);
}
选择计时器Interval
,不要失望,它看起来会有些不均匀. Winforms在动画方面真的很烂.
如果您还希望图像旋转,则可以找到 解决方案
This may help:
float angle = 0;
float rotSpeed = 1;
Point origin = new Point(222, 222); // your origin
int distance = 100; // your distance
private void timer1_Tick(object sender, EventArgs e)
{
angle += rotSpeed;
int x = (int)(origin.X + distance * Math.Sin(angle *Math.PI / 180f));
int y = (int)(origin.Y + distance * Math.Cos(angle *Math.PI / 180f));
yourControl.Location = new Point(x, y);
}
Pick your timer Interval
and don't be disappointed that it will look a little uneven. Winforms is really bad at animation..
If you want the image to rotate as well you can find an example here.
这篇关于如何围绕一个点旋转图片框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文