using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Graphics1 { /// This is the first grahics example from class on 7/9/07. /// This program does some simple drawing when Button1 is clicked. /// The drawing is not persistent--it disappears if the program /// is minimized or covered by something else and then uncovered. /// Button2 also demonstrates the lack of persistence by invalidating /// all or part of the image (depending on which line you use). When /// this happens, there is nothing to redraw the image. public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Blue, 5); g.DrawRectangle(p, 10, 10, 250, 250); p.Dispose(); //We should call Dispose since we created the Pen and g.Dispose(); //Graphics object } private void button2_Click(object sender, EventArgs e) { // Invalidate(); Invalidate(new Rectangle(0, 0, 100, 100)); } } }