C# 控制正反转的"旋转木马"(WinForm)

C# 控制正反转的"旋转木马"(WinForm)

首页音乐舞蹈FNF翻转翻转更新时间:2024-09-22

控制正反转与变量:

private Timer animationTimer; private int rotationAngle = 0; private bool isClockwise = true; private void AnimationTimer_Tick(object sender, EventArgs e) { if (isClockwise) { rotationAngle = 10; if (rotationAngle >= 360) { rotationAngle = 0; } } else { rotationAngle -= 10; if (rotationAngle <= 0) { rotationAngle = 360; } } this.Invalidate(); // 触发窗体重绘 }

绘制图案:

protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int centerX = this.ClientSize.Width / 2; int centerY = this.ClientSize.Height / 2; e.Graphics.TranslateTransform(centerX, centerY); e.Graphics.RotateTransform(rotationAngle); Pen radarPen = new Pen(Color.Fuchsia, 2); Pen radarPen1 = new Pen(Color.White, 2); Font font = new Font("Arial", 40); stringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; for (int i = 0; i < 10; i ) { float angle = i * 36; float x = (float)(150 * Math.Sin(angle * Math.PI / 180)); float y = (float)(-150 * Math.Cos(angle * Math.PI / 180)); e.Graphics.DrawLine(radarPen, 0, 0, x, y); // 使用SolidBrush来填充圆形 SolidBrush solidBrush = new SolidBrush(Color.Fuchsia); e.Graphics.FillEllipse(solidBrush, x - 40, y - 40, 80, 80); SizeF textSize = e.Graphics.MeasureString(((char)('A' i)).ToString(), font); e.Graphics.DrawString(((char)('A' i)).ToString(), font, Brushes.White, x 20 - textSize.Width / 4, y 20 - textSize.Height / 4, stringFormat); } e.Graphics.ResetTransform(); }



查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved