.netvb.netgdi+brushpen

Converting From Brush/Pens To Color


I am making a paint program and the color of the PictureBox Graphics supports Brushes in FillShape and Pens in DrawShape.

If you have any solution please tell me how to convert Brush/Pens to Color? So I can also use ColorDialog for custom colors.


Solution

  • I think what you want is to be able to create a brush or pen from a colour. In that case this should do it:

            'create a brush from a known colour
            Dim brush = New SolidBrush(Color.AliceBlue)
            'create a brush from a user defined colour
            Dim brush2 = New SolidBrush(Color.FromArgb(128, 128, 128))
            'create a pen from a known colour
            Dim pen = New Pen(Color.Red)
            'create a pen from a custom colour
            Dim pen2 = New Pen(Color.FromArgb(0, 128, 255))
            'create a pen from a brush
            Dim pen3 = New Pen(brush)
    
            'don't forget to dispose of your brushes/pens when finished
            brush.Dispose()
            brush2.Dispose()
            pen.Dispose()
            pen2.Dispose()
            pen3.Dispose()