O'Reilly logo

Windows Forms Programming in C# by Chris Sells

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required