I want to make a form with round corners.
Kind of like the shape control with Shape property = "4 - Rounded Rectangle" ?
Printable View
I want to make a form with round corners.
Kind of like the shape control with Shape property = "4 - Rounded Rectangle" ?
Try this:VB Code:
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 MakeRound(frm As Form) Dim lngNewWnd As Long Dim lngNewRgn As Long Dim lngWidth As Long Dim lngHeight As Long ' Calculate the current width lngWidth = frm.Width / Screen.TwipsPerPixelX ' Calculate the current height lngHeight = frm.Height / Screen.TwipsPerPixelY ' Create the new region lngNewWnd = CreateEllipticRgn(0, 0, lngWidth, lngHeight) ' Apply the new region lngNewRgn = SetWindowRgn(frm.hWnd, lngNewWnd, True) End Sub Private Sub Form_Load() 'To make a circular form MakeRound Me End Sub
Yea, that's pretty close...
But it's too big... how do I make it so it rounds only a little bit of the corners ?
Nevermind, I found out how to do it.
I changed from CreateEllipticRgn to CreateRoundRectRgn, like this:
VB Code:
lngNewWnd = CreateRoundRectRgn(0, 0, _ Me.Width / Screen.TwipsPerPixelX + 1, Me.Height / Screen.TwipsPerPixelY + 1, _ 30, 30)
I like it. It is very subtle. :thumb:Quote:
Originally Posted by CVMichael
Wow, do I like this.
I have been looking for a way to round the corners of my picturebox,
which I am using as a command button.
I want to do this so I can establish a background image, and draw some text on it (caption), and I also change the border color on mouseover (and back on mouseover the form).
But the picturebox has square corners, and I want round corners.
This code (modified a bit) does exactly what I want.
FINALLY !!!!!
Thanks guys
Antithesus, Thanks would be much appreciated if you might think of posting your modified version as well
OK, I'll post the whole thing.....
but I'll create a new thread, and NOT Hijack this one.
still better post it in the code bank :thumb: :wave:Quote:
but I'll create a new thread, and NOT Hijack this one
It might be worth mentioning here that this CALL -
Private Declare Function DeleteObject _
Lib "gdi32" (ByVal hObject As Long) As Long
is useful for freeing up the lngNewRgn when you are finished using it...VB will not do this for you...
hi Hack,
any component or reference required ?
quote:
thanksCode:'"Private Declare Function CreateEllipticRgn Lib "gdi32" _"
Private Declare Function CreateRoundRectRgn 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 MakeRound(frm As Form)
Dim lngNewWnd As Long
Dim lngNewRgn As Long
Dim lngWidth As Long
Dim lngHeight As Long
' Calculate the current width
lngWidth = frm.Width / Screen.TwipsPerPixelX
' Calculate the current height
lngHeight = frm.Height / Screen.TwipsPerPixelY
' Create the new region
'lngNewWnd = CreateEllipticRgn(0, 0, lngWidth, lngHeight)
lngNewWnd = CreateRoundRectRgn(0, 0, _
Me.Width / Screen.TwipsPerPixelX + 1, Me.Height / Screen.TwipsPerPixelY + 1, _
30, 30)
' Apply the new region
lngNewRgn = SetWindowRgn(frm.hWnd, lngNewWnd, True)
End Sub
Private Sub Form_Load()
MakeRound Me
End Sub
cesin
No...it should work as is.
thanks for replay
Code:'"Private Declare Function CreateEllipticRgn Lib "gdi32" _"
Private Declare Function CreateRoundRectRgn 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
this code come with compile errorCode:Private Sub MakeRound(frm As Form)
Dim lngNewWnd As Long
Dim lngNewRgn As Long
Dim lngWidth As Long
Dim lngHeight As Long
' Calculate the current width
lngWidth = frm.Width / Screen.TwipsPerPixelX
' Calculate the current height
lngHeight = frm.Height / Screen.TwipsPerPixelY
' Create the new region
'lngNewWnd = CreateEllipticRgn(0, 0, lngWidth, lngHeight)
lngNewWnd = CreateRoundRectRgn(0, 0, _
Me.Width / Screen.TwipsPerPixelX + 1, Me.Height / Screen.TwipsPerPixelY + 1, _
30, 30)
' Apply the new region
lngNewRgn = SetWindowRgn(frm.hWnd, lngNewWnd, True)
End Sub
Private Sub Form_Load()
MakeRound Me
End Sub
"Wrong number of argument or invalid property assignment" on bolt text
Regard,
cesin
The declaration you have is wrong, it should be this:
Code:Public Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Thanks cvmichael for respond
It come with a "compile error, constant, fix-lenght string,arrays,user-defines types and declare statement not allowed as Public members of object module"
on Public Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Regards,
cesin
Normally this is a must with any GDI Objects you create, this is one of the exceptions.Quote:
Originally Posted by sigid
Quote:
Originally Posted by MSDN
So change the Public to Private then...Quote:
Originally Posted by ksuwanto8ksd
I guess you have this code in a Class or a Form where it needs to be Private, I usually put Declarations in a Module, where it usually is Public...
oh ya great
thanks cvmichael
To Milk:
- Thanks for the link! "I was unaware of that!":D
Thanks for this. It works great!
Is it possible to have only the two top corners of the form rounded?
My form to be rounded is a pop up window attached to a main form. It would be cool if the bottom corners could remain sharp corners.
Thanks
:Ron
You can use a mask picture to create regions:
http://thescarms.com/VBasic/IrregularForms.aspx