正文

GDI+: Solid Brushes2006-06-19 20:22:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/iamben250/16024.html

分享到:

Introduction

The simplest type of brush is referred to as solid. This type of brush is simply equipped with a color and it is used to fill a shape with it. To get a solid brush, you use the SolidBrush class defined in the System.Drawing namespace. It has only one constructor declared with the following syntax:

Public Sub New(ByVal color As Color )

The color passed as argument must be a valid definition of a Color. Here is an example:

Private Sub Form1_Paint(ByVal sender As Object, _
	ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim brushBlue As New SolidBrush(Color.Blue)

        e.Graphics.FillRectangle(brushBlue, 20, 20, 200, 160)
End Sub

If you plan to use different colors to fill different shapes, you don't have to create a new brush for each shape. At any time, before re-using the same brush previously defined, you can simply change its Color. For this reason, the SolidBrush class is equipped with the Color property. Here is an example of using it:

Private Sub Form1_Paint(ByVal sender As Object, _
	ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim colorizer As New SolidBrush(Color.Lime)
        e.Graphics.FillRectangle(colorizer, 10, 10, 120, 120)

        colorizer.Color = Color.Salmon
        e.Graphics.FillRectangle(colorizer, 140, 10, 120, 120)

        colorizer.Color = Color.Aqua
        e.Graphics.FillRectangle(colorizer, 10, 140, 120, 120)

        colorizer.Color = Color.Navy
        e.Graphics.FillRectangle(colorizer, 140, 140, 120, 120)
End Sub
Solid Brushes

Like most objects used in graphics programming, a brush consumes the computer resources. Therefore, after using it, you can free the resources it was using by calling the Dispose() method. Here is an example:

Private Sub Form1_Paint(ByVal sender As Object, _
	ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim colorizer As New SolidBrush(Color.Lime)
        e.Graphics.FillRectangle(colorizer, 10, 10, 120, 120)

        colorizer.Color = Color.Salmon
        e.Graphics.FillRectangle(colorizer, 140, 10, 120, 120)

        colorizer.Color = Color.Aqua
        e.Graphics.FillRectangle(colorizer, 10, 140, 120, 120)

        colorizer.Color = Color.Navy
        e.Graphics.FillRectangle(colorizer, 140, 140, 120, 120)

        colorizer.Dispose()
End Sub

 

阅读(2880) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册