-
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.
-
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.
-
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.
-
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. :)
-
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 :D or you can go to you r local drug dealer and buy some shroomz, then you can change the shape of anything! ;)
-
1 Attachment(s)
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...)
-
But it will change the window region only. It will change the button shape. Am I correct?
-
it does change the Command button region, as the result, you'll see the effect of different pattern of command button shape too.
-
Hai,
Yes, You are correct.
Thanx
-
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
-
amitabh, you're absolutely right! :)