private void Form1_Paint(object sender, PaintEventArgs e) { // Do some painting here // Creates an instance of a brush that paints an area with a solid color. SolidBrush myBrush = new SolidBrush(Color.Red); // Adds a rectangle to the list of updates that need to be painted. e.Graphics.FillRectangle(myBrush, new Rectangle(10, 10, 50, 50)); // Dispose of the brush myBrush.Dispose(); }
private void Form1_Paint(object sender, PaintEventArgs e) { // Do some painting here // Dispose of the PaintEventArgs object e.Dispose(); }In this example, we dispose of the PaintEventArgs object manually in the Paint event. This can be useful if the Paint event is raised a large number of times and the resources used by the PaintEventArgs object are no longer needed. Package library: System.Windows.Forms.dll