Brushes

The System.Drawing.Brush class serves as a base class for several kinds of brushes, depending on your needs. Figure 4.3 shows the five derived brush classes provided in the System.Drawing and System.Drawing.Drawing2D namespaces.

Figure 4.3. Sample Brushes

Figure 4.3 was created with the following code:

void BrushesForm_Paint(object sender, PaintEventArgs e) {
  Graphics g = e.Graphics;
  int x = 0;
  int y = 0;
  int width = this.ClientRectangle.Width;
  int height = this.ClientRectangle.Height/5;
  Brush whiteBrush = System.Drawing.Brushes.White;
  Brush blackBrush = System.Drawing.Brushes.Black;

  using( Brush brush = new SolidBrush(Color.DarkBlue) ...

Get Windows Forms Programming in C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.