0

I'm trying to create a custom button for an application in VB.net: more specifically, this is what I'd like my control to look like.

Custom Button

I've managed to find a tutorial explaining how to reshape a control using GraphicsPath, and thanks to that I've managed to bring the button to that size: however, after doing that I can't draw the other pieces of the picture. This is the code I've been using:

Protected Overrides Sub OnPaint(e As PaintEventArgs)

    Dim factor As Integer = Me.Width / 12
    Dim pts() As Point = {
        New Point(0, 0),
        New Point(factor * 12, 0),
        New Point(factor * 12, factor * 4),
        New Point(factor * 8, factor * 8),
        New Point(0, factor * 8)
    }

    Dim polygonPath As New GraphicsPath(FillMode.Winding)
    polygonPath.AddPolygon(pts)

    Dim polygonRegion = New Region(polygonPath)
    Me.Region = polygonRegion

    e.Graphics.FillRectangle(Brushes.Blue, New Rectangle(factor, factor, factor * 7, factor * 6))

    MyBase.OnPaint(e)

End Sub

Am I doing something wrong? Can anyone tell me how to draw the remaining shapes on the button?

  • Never do anything in the Paint event handler that forces the control to be repainted. Like setting the Region property. That code belongs in OnResize(). – Hans Passant Apr 10 '16 at 15:49
  • I see. I've tried to switch it to OnResize() but when I change the control size the shape goes back to a rectangle. Do you know if there's another way to do something like this? – Carlo Piras Apr 10 '16 at 17:41
  • http://stackoverflow.com/a/2896861/17034 – Hans Passant Apr 10 '16 at 17:55
  • Thank you, I'll try that! Can I give you credit for the answer through the comment, or can I do it only if it's a proper answer? – Carlo Piras Apr 10 '16 at 19:31

0 Answers0