Results 1 to 4 of 4

Thread: How to create a command button ??

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Chennai, India
    Posts
    17

    Unhappy

    Hi Everybody

    I wanted a creat a Oval shaped command button ??? pl. tell me how to create ?? is it possible to create thru VB6 ???

    Thanks in advance

    sanju

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Exclamation Everything's possible! Well, not everything, but this is...

    Put this code behind your form:
    Code:
    Option Explicit
    
    Private Declare Function CreateEllipticRgnIndirect Lib "gdi32" (lpRect As RECT) As Long
    Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
    
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    
    Private Sub MakeOval(Ctl As Control)
        Dim RC As RECT, hRgn As Long
        
        Call GetWindowRect(Ctl.hWnd, RC)
        
        RC.Right = RC.Right - RC.Left
        RC.Bottom = RC.Bottom - RC.Top
        RC.Left = 0: RC.Top = 0
        
        hRgn = CreateEllipticRgnIndirect(RC)
        Call SetWindowRgn(Ctl.hWnd, hRgn, True)
        
        Call DeleteObject(hRgn)
    End Sub
    Then use the MakeOval sub.
    For example, use this code and click the button Command1 to make itself become oval-shaped.
    Code:
    Private Sub Command1_Click()
        Call MakeOval(Command1)
    End Sub

  3. #3
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535

    Unhappy

    The Oval command button does not look complete. Only the sides are visible.

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Exclamation Yes...

    It doesn't redraw the borders.
    It just draws an imaginary ellipse on the button, and cuts away whatever's not in it.
    You can also create an oval button by creating an oval picture and putting it in the Picture property of the button. If you do this, don't forget to set the Style property to Graphical.

    The MakeOval can be used on any control. It can also be used on forms, but you need to change this line:

    Private Sub MakeOval(Ctl As Control)

    To this:

    Private Sub MakeOval(Ctl As Object)

    Now that I think of it, you can use the MakeOval sub to physically change the button to an ellipse, and then use a graphic to change it graphically - then it would be perfect!

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