Paint Invalidate Demonstration : Form Paint « GUI Windows Forms « C# / CSharp Tutorial






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();
  }
}








23.4.Form Paint
23.4.1.FormPaint EventFormPaint Event
23.4.2.Override Paint method for FormOverride Paint method for Form
23.4.3.Paint Invalidate DemonstrationPaint Invalidate Demonstration