Advertisement
qiangqiang101

Rounded Form

May 18th, 2020
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.95 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Imports System.Runtime.InteropServices
  3.  
  4. Public Class RoundedForm
  5.     Inherits Form
  6.  
  7.     <DllImport("Gdi32.dll", EntryPoint:="CreateRoundRectRgn")>
  8.     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
  9.     End Function
  10.  
  11.     Private _angle As Single = 400.0F
  12.     Public Property Angle As Single
  13.         Get
  14.             Return _angle
  15.         End Get
  16.         Set(value As Single)
  17.             _angle = value
  18.             Invalidate()
  19.         End Set
  20.     End Property
  21.  
  22.     Public Property Alpha As Integer = 255
  23.     Public Property BackColor2 As Color = BackColor
  24.     Public Property BackColor3 As Color = BackColor
  25.  
  26.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  27.         Dim g As Graphics = e.Graphics
  28.         g.SmoothingMode = SmoothingMode.AntiAlias
  29.         Dim brush As New LinearGradientBrush(New Point(Me.Width / 2, 0), New Point(Me.Width / 2, Me.Height), Color.FromArgb(Alpha, BackColor3), Color.FromArgb(Alpha, BackColor2))
  30.         g.FillRectangle(brush, ClientRectangle)
  31.         Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, _angle, _angle))
  32.         MyBase.OnPaint(e)
  33.     End Sub
  34.  
  35.     Protected Overrides Sub OnResize(eventargs As EventArgs)
  36.         MyBase.OnResize(eventargs)
  37.  
  38.         Invalidate()
  39.     End Sub
  40.  
  41.     Public Sub New()
  42.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  43.         SetStyle(ControlStyles.UserPaint, True)
  44.         DoubleBuffered = True
  45.         FormBorderStyle = BorderStyle.None
  46.         StartPosition = FormStartPosition.CenterScreen
  47.         MaximizeBox = False
  48.         MinimizeBox = False
  49.         ShowInTaskbar = False
  50.         ShowIcon = False
  51.  
  52.         Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, _angle, _angle))
  53.     End Sub
  54.  
  55. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement