各位大侠帮小弟看看这段程序,我画出了系统的时间,但是当它动态画的时候,一直是覆盖跳动的,我加了个Refresh,但是不怎么好,太闪了,要怎么才能实现刷新而不重叠呢?谢谢了!(将代码直接复制就可以运行)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace waDrawingTime
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.btnStart = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 96);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(432, 88);
this.label1.TabIndex = 0;
//
// btnStart
//
this.btnStart.BackColor = System.Drawing.Color.LightSeaGreen;
this.btnStart.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnStart.ForeColor = System.Drawing.Color.Black;
this.btnStart.Location = new System.Drawing.Point(24, 32);
this.btnStart.Name = "btnStart";
this.btnStart.TabIndex = 3;
this.btnStart.Text = "Start";
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(400, 237);
this.Controls.Add(this.btnStart);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnStart_Click(object sender, System.EventArgs e)
{
this.timer1.Start();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
System.Drawing.Drawing2D.LinearGradientBrush myBrush2 = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,Color.Red, Color.Red, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
System.Drawing.Graphics labelGraphics = this.label1.CreateGraphics();
System.Drawing.Font DrawFont = new System.Drawing.Font("Arial", 30);
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
System.Drawing.RectangleF rec = new System.Drawing.RectangleF();
labelGraphics.DrawString(System.DateTime.Now.ToString(("yyyy/MM/dd" + " " + "HH:mm:ss")),DrawFont,myBrush2,rec,drawFormat);
//this.label3.Refresh();
}
}
}
[此贴子已经被作者于2006-8-26 13:17:23编辑过]