Skip to content

Instantly share code, notes, and snippets.

@ninoslat1
Last active September 27, 2024 06:48
Show Gist options
  • Save ninoslat1/ae9315549cfb511f88ce7fecee450211 to your computer and use it in GitHub Desktop.
Save ninoslat1/ae9315549cfb511f88ce7fecee450211 to your computer and use it in GitHub Desktop.
Rounded Panel Visual Basic Forms Component
'For use this as custom component. Click Add > New Item > User Control (Windows Forms) and paste this code
Imports System.Runtime.InteropServices
Public Class RoundedPanel
<DllImport("Gdi32.dll", EntryPoint:="CreateRoundRectRgn")>
Private Shared Function CreateRoundRectRgn(
ByVal nLeftRect As Integer,
ByVal nTopRect As Integer,
ByVal nRightRect As Integer,
ByVal nBottomRect As Integer,
ByVal nWidthEllipse As Integer,
ByVal nHeightEllipse As Integer) As IntPtr
End Function
Private roundedVal As Integer = 40 'Edit this value for more rounded edges
Private Sub RoundedPanel_Load(sender As Object, e As EventArgs)
Dim innerPanel As New Panel
innerPanel.Dock = DockStyle.Fill
innerPanel.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, innerPanel.Width, innerPanel.Height, roundedVal, roundedVal))
Me.Controls.Add(innerPanel)
End Sub
Private Sub RoundedPanel_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
Dim roundedRegion As Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Me.Width, Me.Height, roundedVal, roundedVal))
Me.Region = roundedRegion
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment