
C#如何画出一个一直在旋转的动态矩形?
1个回答
2014-01-24
展开全部
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
static Graphics g;
Pen p = new Pen(Color.Blue, 5);
public Form1()
{
InitializeComponent();
System.Timers.Timer t = new System.Timers.Timer(100);
t.Elapsed += new System.Timers.ElapsedEventHandler(TWork);
t.AutoReset = true;
t.Enabled = true;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
g = this.CreateGraphics();
g.TranslateTransform(200, 100);
}
private delegate void timer();
private void TWork(object sender, System.Timers.ElapsedEventArgs e)
{
if (this.IsHandleCreated)
{
this.BeginInvoke(new timer(SetStatus));
}
}
private void SetStatus()
{
g.Clear(this.BackColor);
g.RotateTransform(5);
g.DrawLine(p, new Point(20, 20), new Point(50, 20));
g.DrawLine(p, new Point(20, 20), new Point(20, 50));
g.DrawLine(p, new Point(50, 50), new Point(20, 50));
g.DrawLine(p, new Point(50, 50), new Point(50, 20));
}
}
}
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
static Graphics g;
Pen p = new Pen(Color.Blue, 5);
public Form1()
{
InitializeComponent();
System.Timers.Timer t = new System.Timers.Timer(100);
t.Elapsed += new System.Timers.ElapsedEventHandler(TWork);
t.AutoReset = true;
t.Enabled = true;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
g = this.CreateGraphics();
g.TranslateTransform(200, 100);
}
private delegate void timer();
private void TWork(object sender, System.Timers.ElapsedEventArgs e)
{
if (this.IsHandleCreated)
{
this.BeginInvoke(new timer(SetStatus));
}
}
private void SetStatus()
{
g.Clear(this.BackColor);
g.RotateTransform(5);
g.DrawLine(p, new Point(20, 20), new Point(50, 20));
g.DrawLine(p, new Point(20, 20), new Point(20, 50));
g.DrawLine(p, new Point(50, 50), new Point(20, 50));
g.DrawLine(p, new Point(50, 50), new Point(50, 20));
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询