用C#的GDI+绘制一个会走动的时钟,可是我找网上的方法把代码弄了,运行起来时钟就是不动,怎么让他动起来
protectedoverridevoidOnPaint(PaintEventArgse){SolidBrushblack=newSolidBrush(Color.Bla...
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush black = new SolidBrush(Color.Black);
//初始化数据
InitializeTransform(e.Graphics);
//绘制表盘上表示小格的小方块
for (int i = 0; i < 60; i++)
{
e.Graphics.RotateTransform(6.0f);
e.Graphics.FillRectangle(black, 85, 0, 8, 1);
}
//绘制表盘上表示小时的小方块
for (int i = 0; i < 12; i++)
{
e.Graphics.FillRectangle(black, 85, -5, 10, 10);
}
DateTime now = DateTime.Now;
int second = now.Second;
int minute = now.Minute;
int hour = now.Hour % 12;
//重新初始化转换矩阵
InitializeTransform(e.Graphics);
//绘制时针
e.Graphics.RotateTransform((hour * 30) + (minute / 2) + (second / 600));
DrawHand(e.Graphics, blue, 45, 12);
//重新初始化转换矩阵
InitializeTransform(e.Graphics);
//绘制分针
e.Graphics.RotateTransform((minute * 6) + (second / 10));
DrawHand(e.Graphics, red, 60, 9);
//重新初始化转换矩阵
InitializeTransform(e.Graphics);
//绘制秒针
e.Graphics.RotateTransform(second * 6);
DrawHand(e.Graphics, yellow, 90, 6);//释放画笔
black.Dispose();
上面的DrawHand和 InitializeTransform函数由于字数限制打不出来要怎么使他动 展开
{
SolidBrush black = new SolidBrush(Color.Black);
//初始化数据
InitializeTransform(e.Graphics);
//绘制表盘上表示小格的小方块
for (int i = 0; i < 60; i++)
{
e.Graphics.RotateTransform(6.0f);
e.Graphics.FillRectangle(black, 85, 0, 8, 1);
}
//绘制表盘上表示小时的小方块
for (int i = 0; i < 12; i++)
{
e.Graphics.FillRectangle(black, 85, -5, 10, 10);
}
DateTime now = DateTime.Now;
int second = now.Second;
int minute = now.Minute;
int hour = now.Hour % 12;
//重新初始化转换矩阵
InitializeTransform(e.Graphics);
//绘制时针
e.Graphics.RotateTransform((hour * 30) + (minute / 2) + (second / 600));
DrawHand(e.Graphics, blue, 45, 12);
//重新初始化转换矩阵
InitializeTransform(e.Graphics);
//绘制分针
e.Graphics.RotateTransform((minute * 6) + (second / 10));
DrawHand(e.Graphics, red, 60, 9);
//重新初始化转换矩阵
InitializeTransform(e.Graphics);
//绘制秒针
e.Graphics.RotateTransform(second * 6);
DrawHand(e.Graphics, yellow, 90, 6);//释放画笔
black.Dispose();
上面的DrawHand和 InitializeTransform函数由于字数限制打不出来要怎么使他动 展开
1个回答
展开全部
这里只是提供了画的方法,
要动就要不停地画,要一直调用这个控件的Invalidate方法。
要动就要不停地画,要一直调用这个控件的Invalidate方法。
追问
我用了,但是还是没反应,要怎么调用
追答
System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
myTimer.Tick += new EventHandler(TimerEventProcessor);
myTimer.Interval = 500;
myTimer.Start();
// This is the method to run when the timer is raised.
private static void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
control.Invalidate();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询