我正在尝试编写一个程序来显示带有 PictureBox 的 Wii 遥控器的旋转。当 Wii Remote 在 X 轴上旋转时,Wii Remote 的图片也会随之旋转。旋转的值已经显示在一个文本框中,它看起来像这样:0.109243284720305
或-0.132414335
。
我将如何使用这些值来旋转显示的图像?
创建从 PictureBox 继承的自定义控件并覆盖 OnPaint 虚拟方法以根据需要绘制 wiimote 位图:
public partial class WiiMoteControl: PictureBox {
public Bitmap wiimote;
private float _angle;
public float Angle {
get { return _angle; }
set { _angle = value; Invalidate( ); }
}
protected override void OnPaint( PaintEventArgs pe ) {
base.OnPaint( pe );
pe.Graphics.ResetTransform( );
pe.Graphics.TranslateTransform( Size.Width / 2, Size.Height / 2 );
pe.Graphics.RotateTransform( Angle );
pe.Graphics.TranslateTransform( -Size.Width / 2, -Size.Height / 2 );
if (wiimote != null) {
pe.Graphics.DrawImage( wiimote, 0, 0, Size.Width, Size.Height );
}
}
}