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
Printable View
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
Put this code behind your form:
Then use the MakeOval sub.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
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
The Oval command button does not look complete. Only the sides are visible.
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! :D