using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Graphics3 { /// This is the third graphics example from class on 7/9/07. /// This program overrides the built-in OnPaint method and /// does the drawing there. It also counts the calls of OnPaint /// and displays the count in a text box. This code follws the /// .NET recommendation and calls base.OnPaint. public partial class Form3 : Form { int nPaints = 0; public Form3() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; Pen p = new Pen(Color.Red, 5); g.DrawRectangle(p, 10, 10, 240, 240); p.Dispose(); nPaints++; textBox1.Text = nPaints.ToString(); } } }