Results 1 to 1 of 1

Thread: Round the corners on a form or control

  1. #1

    Thread Starter
    New Member George B Gilbert's Avatar
    Join Date
    Apr 2024
    Location
    Genesee, Idaho
    Posts
    7

    Round the corners on a form or control

    Name:  rounded form.jpg
Views: 529
Size:  23.1 KB

    Name:  rounded buttons.jpg
Views: 538
Size:  29.0 KB

    Code:
    Public Class C_RoundCorners
    
        Public Sub RoundCornersForm(Form As Form,
                                    Optional Radius As Integer = 20)
            '---------------------------------------------------------------------------------
            ' Round the corners on a form
            '---------------------------------------------------------------------------------
    
            Form.FormBorderStyle = FormBorderStyle.None
            Dim DGP As New Drawing2D.GraphicsPath
            DGP.StartFigure()
    
            '** Top left corner
            DGP.AddArc(New Rectangle(0, 0, Radius, Radius), 180, 90)
            DGP.AddLine(Radius, 0, Form.Width - Radius, 0)
    
            '** Top right corner
            DGP.AddArc(New Rectangle(Form.Width - Radius, 0, Radius, Radius), -90, 90)
            DGP.AddLine(Form.Width, Radius, Form.Width, Form.Height - Radius)
    
            '** Bottom right corner
            DGP.AddArc(New Rectangle(Form.Width - Radius, Form.Height - Radius, Radius, Radius), 0, 90)
            DGP.AddLine(Form.Width - Radius, Form.Height, Radius, Form.Height)
    
            '** Bottom left corner
            DGP.AddArc(New Rectangle(0, Form.Height - Radius, Radius, Radius), 90, 90)
            DGP.CloseFigure()
    
            Form.Region = New Region(DGP)
    
        End Sub
        Public Sub RoundCornersControl(Control As Control,
                                       Optional Radius As Integer = 5)
            '---------------------------------------------------------------------------------
            ' Round the corners on a control
            '---------------------------------------------------------------------------------
    
            Dim DGP As New Drawing2D.GraphicsPath
            DGP.StartFigure()
    
            '** Top left corner
            DGP.AddArc(New Rectangle(0, 0, Radius, Radius), 180, 90)
            DGP.AddLine(Radius, 0, Control.Width - Radius, 0)
    
            '** Top right corner
            DGP.AddArc(New Rectangle(Control.Width - Radius, 0, Radius, Radius), -90, 90)
            DGP.AddLine(Control.Width, Radius, Control.Width, Control.Height - Radius)
    
            '** Bottom right corner
            Dim brRadius As Integer = Radius + 5
            DGP.AddArc(New Rectangle(Control.Width - brRadius, Control.Height - brRadius, brRadius, brRadius), 0, 90)
            DGP.AddLine(Control.Width - brRadius, Control.Height, brRadius, Control.Height)
    
            '** Bottom left corner
            Dim blRadius As Integer = Radius + 3
            DGP.AddArc(New Rectangle(0, Control.Height - blRadius, blRadius, blRadius), 90, 90)
            DGP.CloseFigure()
    
            Control.Region = New Region(DGP)
    
        End Sub
    End Class
    Last edited by George B Gilbert; Apr 24th, 2024 at 10:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width