Export (0) Print
Expand All

SolidBrush Class

Defines a brush of a single color. Brushes are used to fill graphics shapes, such as rectangles, ellipses, pies, polygons, and paths. This class cannot be inherited.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

public sealed class SolidBrush : Brush
public final class SolidBrush extends Brush
public final class SolidBrush extends Brush
Not applicable.

This class inherits from the Brush class.

  • The following code example adds a shadow to a ListBox using a SolidBrush.

This example is designed to be used with a Windows Form. To run this example, paste this code into a form and call the AddShadow method when handling the form's Paint event. Make sure the form contains a ListBox named listBox1.

private void AddShadow(PaintEventArgs e)
{

    // Create two SizeF objects.
    SizeF shadowSize = listBox1.Size;
    SizeF addSize = new SizeF(10.5F, 20.8F);

    // Add them together and save the result in shadowSize.
    shadowSize = shadowSize + addSize;

    // Get the location of the ListBox and convert it to a PointF.
    PointF shadowLocation = listBox1.Location;

    // Add two points to get a new location.
    shadowLocation = shadowLocation + new Size(5, 5);

    // Create a rectangleF. 
    RectangleF rectFToFill = 
        new RectangleF(shadowLocation, shadowSize);

    // Create a custom brush using a semi-transparent color, and 
    // then fill in the rectangle.
    Color customColor = Color.FromArgb(50, Color.Gray);
    SolidBrush shadowBrush = new SolidBrush(customColor);
    e.Graphics.FillRectangles(shadowBrush, new RectangleF[]{rectFToFill});

    // Dispose of the brush.
    shadowBrush.Dispose();
}

private void AddShadow(PaintEventArgs e)
{
    // Create two SizeF objects.
    SizeF shadowSize = Size.op_Implicit(listBox1.get_Size());
    SizeF addSize = new SizeF(10.5F, 20.8F);

    // Add them together and save the result in shadowSize.
    shadowSize.set_Width(shadowSize.get_Width() + addSize.get_Width());
    shadowSize.set_Height(shadowSize.get_Height() + addSize.get_Height());

    // Get the location of the ListBox and convert it to a PointF.
    PointF shadowLocation = Point.op_Implicit(listBox1.get_Location());

    // Add two points to get a new location.
    shadowLocation.set_X(shadowLocation.get_X()  
        + (new Size(5, 5).get_Width()));
    shadowLocation.set_Y(shadowLocation.get_Y()  
        + (new Size(5, 5).get_Height()));
    
    // Create a rectangleF. 
    RectangleF rectFToFill = new RectangleF(shadowLocation, shadowSize);

    // Create a custom brush using a semi-transparent color, and 
    // then fill in the rectangle.
    Color customColor = Color.FromArgb(50, Color.get_Gray());
    SolidBrush shadowBrush = new SolidBrush(customColor);

    e.get_Graphics().FillRectangles(shadowBrush, 
        new RectangleF[] { rectFToFill });

    // Dispose of the brush.
    shadowBrush.Dispose();
} //AddShadow

System.Object
   System.MarshalByRefObject
     System.Drawing.Brush
      System.Drawing.SolidBrush

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft