Results 1 to 11 of 11

Thread: Changing the Shape of Command Buttons

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Ontario, Canada
    Posts
    3

    Question

    Greetings.

    I'm currently working on a personal project to aid myself in honing my programming skills.

    In this project, there are a number of different command buttons on a number of different forms.

    For purely aesthetic reasons, I'd like to change the shape of the command buttons from the default rectangular, to say, an oval.

    Is there a way to accomplish this through standard VB code?

    I understand that shapes can be drawn and can simulate command buttons via the various *mouse events, but I'd prefer to stay away from doing that way if it's at all possible.

    Thanks in advance.
    _.-=[ ~ Vermithrax ~ ]=-._

  2. #2
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Easy, use the SetWindowRgn API.

    Code:
    Private Declare Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Assuming that you know about APIs. Otherwise, I'll explain FURther.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  3. #3
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Oh, yes, and you need to draw on the buttons anyway.

    SetWindowRgn merely causes NOTHING to happen when the mouse (or some other rodent) clickes on the "GREY" edge. The best way to do it is to use BitBlt to draw "IMAGES" of round buttons or to use the Ellipse API.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Location
    Ontario, Canada
    Posts
    3
    Nope. I have no idea about API's as of yet.
    I'm still in an Intermediate level of instruction for VB.
    Any further instructon would be appreciated.
    _.-=[ ~ Vermithrax ~ ]=-._

  5. #5
    Addicted Member
    Join Date
    Dec 2000
    Posts
    135
    maybe if you change the height and width of the button in a special pattern at the right speed it would look like a round button or you can go to you r local drug dealer and buy some shroomz, then you can change the shape of anything!

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    vermithrax ,here is a quick sample code for you.

    Code:
    Option Explicit
    '//WIN32API Declare
    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 Command1_Click()
        MsgBox "Bingo"
    End Sub
    
    Private Sub Form_Load()
        Dim hRgn As Long
        
        With Command1
            hRgn = CreateEllipticRgn(10, 10, 180, 100)
            SetWindowRgn .hwnd, hRgn, True
        End With
    End Sub
    
    'Code improved by vBulletin Tool (Save as...)
    Attached Files Attached Files

  7. #7
    Lively Member markwel's Avatar
    Join Date
    Jan 2001
    Location
    Chennai, India
    Posts
    104
    But it will change the window region only. It will change the button shape. Am I correct?
    Soma Sundaram R
    3/480, Lakshmana Perumal Street
    Kottivakkam
    Chennai, India

    [email protected]
    http://somasundaram.cjb.com
    Develop Your Own Browser-->http://www.vbsquare.com/internet/browser/

  8. #8
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    it does change the Command button region, as the result, you'll see the effect of different pattern of command button shape too.

  9. #9
    Lively Member markwel's Avatar
    Join Date
    Jan 2001
    Location
    Chennai, India
    Posts
    104
    Hai,

    Yes, You are correct.

    Thanx
    Soma Sundaram R
    3/480, Lakshmana Perumal Street
    Kottivakkam
    Chennai, India

    [email protected]
    http://somasundaram.cjb.com
    Develop Your Own Browser-->http://www.vbsquare.com/internet/browser/

  10. #10
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Also, use the DeleteObject api call after you have used the SetWindowRgn. This will free up the memory.
    From Chris's code
    Code:
    With Command1
            hRgn = CreateEllipticRgn(10, 10, 180, 100)
            SetWindowRgn .hwnd, hRgn, True
            DeleteObject hRgn
    End With

  11. #11
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    amitabh, you're absolutely right!

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