做一个模拟时钟的WinForm程序,用背景图组成一个时钟,背景图分别为表盘背景、分针.png、秒针.png三个图片,为了叠加的时候能够实现透明,自定义了一个控件,控件里分别放分针.png、秒针.png图片。然后在窗口里调用自定义控件,最后想使用定时器每秒旋转放秒针.png的控件,从而实现时钟效果。
public partial class TestDrawingTransparentImage : Form
{
public TestDrawingTransparentImage()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Graphics g = e.Graphics;
Control ct = this.drawingMiaozhen1;//秒针的控件
System.IntPtr mz_handle = ct.Handle;
Graphics g = Graphics.FromHwnd(mz_handle);
g.RotateTransform(180);
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Invalidate();
}
}
运行的时候,测试时1分钟后,旋转函数执行后,窗口什么都没显示。
运行后,测试1分钟后,函数执行后,窗口什么都没有
怎么实现正常旋转呢?求指导啊?