SolidBrush class

A brush that fills a shape with one colour.

A SolidBrush is the simplest of the brushes and implements IBrush. Its colour can have an alpha value, so a fill can be partly transparent. The class mirrors the GDI+ SolidBrush class.

Creating

Syntax: brush = SolidBrush( color )

Syntax: brush = New SolidBrush( color )

Syntax: brush = SolidBrush( rgb )

Syntax: brush = New SolidBrush( rgb )

color
required A Color for the brush. Its alpha value is kept.
rgb
required A Long for the colour, as &H00RRGGBB. The alpha is always 255.
Dim user As GdiPlusUser = GdiPlusUser()

Dim bmp As Bitmap = Bitmap(4!, 4!)
Dim g As Graphics = Graphics(bmp)

Dim brush As SolidBrush = SolidBrush(Color(255, 255, 0, 0))   ' red
g.FillRectangle(brush, 0, 0, 4, 4)
Debug.Print Hex$(bmp.Pixel(1, 1).argb)

Dim wrong As SolidBrush = SolidBrush(RGB(255, 0, 0))          ' blue, not red
g.FillRectangle(wrong, 0, 0, 4, 4)
Debug.Print Hex$(bmp.Pixel(1, 1).argb)
' Output:
' FFFF0000
' FF0000FF

Clone

Syntax: copy = brush.Clone( )

Returns a new SolidBrush with the same colour. Changing the copy does not change the original.

Colour

Color

Syntax: brush.Color [ = color ]

Gets or sets the colour of the brush, as a Color with its alpha value.

RGB

Syntax: brush.RGB [ = rgb ]

Gets or sets the colour as a Long in the form &H00RRGGBB. Reading it drops the alpha value, and writing it sets an opaque colour.

Dim user As GdiPlusUser = GdiPlusUser()

Dim brush As SolidBrush = SolidBrush(Color(128, 10, 20, 30))
Debug.Print Hex$(brush.Color.argb)
Debug.Print Hex$(brush.RGB)

brush.Color = Color(255, 1, 2, 3)
Debug.Print Hex$(brush.RGB)

brush.RGB = &HFF8000
Debug.Print Hex$(brush.Color.argb)
' Output:
' 800A141E
' A141E
' 10203
' FFFF8000

Type

Type

Syntax: type = brush.Type

Returns BrushTypeSolidColor (GpBrushType). The property is read-only.

Example

A partly transparent fill lets what is under it show through. The example fills a bitmap with white and then with half-transparent red.

Dim user As GdiPlusUser = GdiPlusUser()

Dim bmp As Bitmap = Bitmap(4!, 4!)
Dim g As Graphics = Graphics(bmp)
g.Clear(Color(255, 255, 255, 255))

Dim glass As SolidBrush = SolidBrush(Color(128, 255, 0, 0))
g.FillRectangle(glass, 0, 0, 2, 4)

Dim covered As Color = bmp.Pixel(0, 0)
Dim bare As Color = bmp.Pixel(3, 0)
Debug.Print Hex$(covered.R) & " " & Hex$(covered.G)
Debug.Print Hex$(bare.R) & " " & Hex$(bare.G)

Dim clone As SolidBrush = glass.Clone()
clone.Color = Color(255, 0, 0, 255)
Debug.Print Hex$(glass.Color.argb) & " " & Hex$(clone.Color.argb)
' Output:
' FF 7F
' FF FF
' 80FF0000 FF0000FF

See Also