Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1461

How to Make a Round (Circular) Form

$
0
0
Ever want a round form? This short VB6 code will create it for you. I know it works on XP and Win7. Not tested on Win8.

Open a new VB6 project
I added two shapes and one label to the form---not necessary, but looks pretty! :-)
I use a Double-Click to unload the form, but you can use any ctrl/code you desire.

Code:

Option Explicit
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Sub Form_DblClick()
  Unload Me
End Sub
Private Sub Form_Load()
    Dim lngRegion As Long
    Dim lngReturn As Long
    Dim lngFormWidth As Long
    Dim lngFormHeight As Long
    Me.Width = Me.Height
   
    lngFormWidth = Me.Width / Screen.TwipsPerPixelX
    lngFormHeight = Me.Height / Screen.TwipsPerPixelY
    lngRegion = CreateEllipticRgn(0, 0, lngFormWidth, lngFormHeight)
    lngReturn = SetWindowRgn(Me.hWnd, lngRegion, True)
    Shape1.Left = (Me.Width / 2) - (Shape1.Width / 2)
    Shape2.Left = (Me.Width / 2) - (Shape2.Width / 2)
    Shape1.Top = (Me.Height / 2) - (Shape1.Height / 2)
    Shape2.Top = (Me.Height / 2) - (Shape2.Height / 2)
    Label1.Top = (Me.Height / 2) - (Label1.Height / 2)
    Label1.Left = (Me.Width / 2) - (Label1.Width / 2)
End Sub
Private Sub Label1_Click()
  Unload frmRound
End Sub


Viewing all articles
Browse latest Browse all 1461

Trending Articles