简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM