GDI+ 时钟 求助! 恳请各位指点! 本帖最后由 fghai25 于 2009-12-15 16:32:42 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 m_GraphicsSurface这个没有清理干净,每次都往上面画东西,自然东西越来越多。两个办法解决: 一是每次画之前清干净他。二是干脆不用这个对象,直接往e.Griphics上面画。 不要直接画到表盘图像上,这样搽不掉。表盘可以先准备好,每秒要求重画一次。在重画中先贴表盘,然后画指针(注意timer1_Tick和FrmTimer_Paint的改动): #region 显示指针 /// <summary> /// 时针 /// 1.把坐标系平移到用户区域的中心 /// 2.计算当前时针的角度angle /// 3.在angle度画出当前的时针位置和样式 /// 4.还原坐标系并刷新 /// </summary> private void DrawHourArm(Graphics objGraphics) { objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2); double hourTime = (double)DateTime.Now.Hour + (double)(DateTime.Now.Minute / 60.0); double angle = (hourTime / 12.0) * 360; // 2.0 * Math.PI; objGraphics.RotateTransform(((float)angle) - 178); Pen hHPen = HHPen; hHPen.SetLineCap(LineCap.Square, LineCap.ArrowAnchor, DashCap.Triangle); //线条的起点和终点样式 objGraphics.DrawLine(HHPen, HPoint1, HPoint2); objGraphics.ResetTransform(); } /// <summary> /// 分针 /// </summary> private void DrawMiniteArm(Graphics objGraphics) { objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2); double minuteTime = (double)DateTime.Now.Minute + (double)(DateTime.Now.Second / 60.0); double angle = ((double)minuteTime / 60.0) * 360; // 2.0 * Math.PI; objGraphics.RotateTransform(((float)angle) - 183); Pen mMPen = MMPen; mMPen.SetLineCap(LineCap.Square, LineCap.ArrowAnchor, DashCap.Triangle);//线条的起点和终点样式 objGraphics.DrawLine(mMPen, MPoint1, MPoint2); objGraphics.ResetTransform(); } /// <summary> /// 分针 /// </summary> private void DrawSecondArm(Graphics objGraphics) { objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2); double angle = ((double)DateTime.Now.Second / 60.0) * 360;//角度 objGraphics.RotateTransform(((float)angle) - 180); Pen sSPen = SSPen; sSPen.SetLineCap(LineCap.DiamondAnchor, LineCap.ArrowAnchor, DashCap.Triangle);//线条的起点和终点样式 objGraphics.DrawLine(sSPen, SPoint1, SPoint2); objGraphics.ResetTransform(); } #endregion private void FrmTimer_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawImage(m_GraphicsSurface, 0,0, this.ClientRectangle.Width, this.ClientRectangle.Height); DrawSecondArm( e.Graphics ); // 画秒针 DrawMiniteArm( e.Graphics ); // 画分针 DrawHourArm( e.Graphics ); // 画时针 } /// <summary> /// 每秒跳动一次 /// </summary> private void timer1_Tick(object sender, EventArgs e) { this.textBox1.Text = DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒"); this.Invalidate(); } lsitview索引问题 关于调用事件的问题 看完《C#入门经典》之后应该怎么办? 求C#的网络语音视频聊天室的源程序...或方法...思路...讲解 C# ?δ?????? .net 开源社区大家推荐几个? 如何捕获异常详细信息: System.Net.WebException: 远程服务器返回错误: (404) 未找到 读取文件时出现的怪问题 请教高手!怎样获取一个网络服务的登录帐号?怎样设置一个目录对该帐号的访问权限? 查询方法 DataGridViewCheckBoxColumn如何把dataGridView从数据库中显示的表绑定删除 SetValue
一是每次画之前清干净他。
二是干脆不用这个对象,直接往e.Griphics上面画。
表盘可以先准备好,每秒要求重画一次。在重画中先贴表盘,然后画指针(注意timer1_Tick和FrmTimer_Paint的改动):
#region 显示指针 /// <summary>
/// 时针
/// 1.把坐标系平移到用户区域的中心
/// 2.计算当前时针的角度angle
/// 3.在angle度画出当前的时针位置和样式
/// 4.还原坐标系并刷新
/// </summary>
private void DrawHourArm(Graphics objGraphics)
{
objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2); double hourTime = (double)DateTime.Now.Hour + (double)(DateTime.Now.Minute / 60.0);
double angle = (hourTime / 12.0) * 360; // 2.0 * Math.PI; objGraphics.RotateTransform(((float)angle) - 178);
Pen hHPen = HHPen;
hHPen.SetLineCap(LineCap.Square, LineCap.ArrowAnchor, DashCap.Triangle); //线条的起点和终点样式
objGraphics.DrawLine(HHPen, HPoint1, HPoint2); objGraphics.ResetTransform();
} /// <summary>
/// 分针
/// </summary>
private void DrawMiniteArm(Graphics objGraphics)
{ objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2); double minuteTime = (double)DateTime.Now.Minute + (double)(DateTime.Now.Second / 60.0);
double angle = ((double)minuteTime / 60.0) * 360; // 2.0 * Math.PI;
objGraphics.RotateTransform(((float)angle) - 183);
Pen mMPen = MMPen;
mMPen.SetLineCap(LineCap.Square, LineCap.ArrowAnchor, DashCap.Triangle);//线条的起点和终点样式
objGraphics.DrawLine(mMPen, MPoint1, MPoint2); objGraphics.ResetTransform();
}
/// <summary>
/// 分针
/// </summary>
private void DrawSecondArm(Graphics objGraphics)
{
objGraphics.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height / 2); double angle = ((double)DateTime.Now.Second / 60.0) * 360;//角度
objGraphics.RotateTransform(((float)angle) - 180);
Pen sSPen = SSPen;
sSPen.SetLineCap(LineCap.DiamondAnchor, LineCap.ArrowAnchor, DashCap.Triangle);//线条的起点和终点样式
objGraphics.DrawLine(sSPen, SPoint1, SPoint2); objGraphics.ResetTransform();
}
#endregion
private void FrmTimer_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(m_GraphicsSurface,
0,0,
this.ClientRectangle.Width,
this.ClientRectangle.Height); DrawSecondArm( e.Graphics ); // 画秒针
DrawMiniteArm( e.Graphics ); // 画分针
DrawHourArm( e.Graphics ); // 画时针
} /// <summary>
/// 每秒跳动一次
/// </summary>
private void timer1_Tick(object sender, EventArgs e)
{
this.textBox1.Text = DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒");
this.Invalidate();
}