Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Paint Invalidate Demonstration

using System; using System.Drawing; using System.Windows.Forms; public class PaintInvalidate : Form {   private Button btn;   public PaintInvalidate()   {     Size = new Size(300,200);     btn = new Button();     btn.Parent = this;     btn.Location = new Point(25,25);     btn.Text = "Update";     btn.Click += new System.EventHandler(btn_Click);   }   static void Main()    {     Application.Run(new PaintInvalidate());   }   protected override void OnPaint(PaintEventArgs e)   {     base.OnPaint(e);     Graphics g = e.Graphics;     String str = "\nThe time is " + DateTime.Now.ToLongTimeString();     g.DrawString(str, Font, Brushes.Black, 50, 75);   }   private void btn_Click(object sender, EventArgs e)   {     Invalidate();   } }