Results 1 to 5 of 5

Thread: How to Make a Round (Circular) Form

  1. #1

    Thread Starter
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Wink How to Make a Round (Circular) Form

    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

  2. #2

    Thread Starter
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: How to Make a Round (Circular) Form

    Sorry---those two shapes were circles--to make the form look like a target---one red, one white, the form was red. The Label simply said (Double-Click to unload the form)....I shoulda included this information initially...sorry. BUt, to make the form itself, you can delete all references to the shapes and label and you will have a plain round form.

  3. #3
    Addicted Member ondalor's Avatar
    Join Date
    Jan 2013
    Location
    Washington DC
    Posts
    195

    Re: How to Make a Round (Circular) Form

    very cool but maby you can tell me why the text in the form when set to center horizontally and vertically doesnt endup in the middle?

    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)
    
    End Sub
    Private Sub Label1_Click()
       Unload frmRound
    End Sub
    Name:  Capture.PNG
Views: 2389
Size:  14.2 KB
    Live for the nights you won't remember with the friends you will never forget.

  4. #4

    Thread Starter
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: How to Make a Round (Circular) Form

    Add these two lines (make the label Autosize as well)

    Code:
    Label1.Left = (Me.Width / 2) - (Label1.Width / 2)
    Label1.Top = (Me.Height / 2) - (Label1.Height / 2)
    Also, if you set the form borderstyle to NONE, it looks better, but you can't move it around.

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to Make a Round (Circular) Form

    Quote Originally Posted by SamOscarBrown View Post
    Add these two lines (make the label Autosize as well)

    Code:
    Label1.Left = (Me.Width / 2) - (Label1.Width / 2)
    Label1.Top = (Me.Height / 2) - (Label1.Height / 2)
    Also, if you set the form borderstyle to NONE, it looks better, but you can't move it around.
    Sure you can. Just add this code

    Code:
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    
    Private Const HTCAPTION = 2
    
    Private Const WM_NCLBUTTONDOWN = &HA1
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     If Button = vbLeftButton Then
       ReleaseCapture
       SendMessage Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
     End If
    End Sub


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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