|
-
Sep 7th, 2005, 01:07 PM
#1
[RESOLVED] How to make a form with round corners ?
I want to make a form with round corners.
Kind of like the shape control with Shape property = "4 - Rounded Rectangle" ?
-
Sep 7th, 2005, 01:15 PM
#2
Re: How to make a form with round corners ?
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
-
Sep 7th, 2005, 01:24 PM
#3
Re: How to make a form with round corners ?
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 ?
-
Sep 7th, 2005, 02:08 PM
#4
Re: How to make a form with round 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)
-
Sep 7th, 2005, 02:16 PM
#5
Re: How to make a form with round corners ?
 Originally Posted by CVMichael
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.
-
Sep 28th, 2007, 06:34 PM
#6
Lively Member
Re: [RESOLVED] How to make a form with round corners ?
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
-
Sep 29th, 2007, 12:08 AM
#7
Frenzied Member
Re: [RESOLVED] How to make a form with round corners ?
Antithesus, Thanks would be much appreciated if you might think of posting your modified version as well
-
Sep 29th, 2007, 05:13 PM
#8
Lively Member
Re: [RESOLVED] How to make a form with round corners ?
OK, I'll post the whole thing.....
but I'll create a new thread, and NOT Hijack this one.
-
Oct 4th, 2007, 12:41 AM
#9
Frenzied Member
Re: [RESOLVED] How to make a form with round corners ?
but I'll create a new thread, and NOT Hijack this one
still better post it in the code bank
-
Oct 4th, 2007, 10:39 AM
#10
Addicted Member
Re: [RESOLVED] How to make a form with round corners ?
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...
-
Oct 4th, 2007, 12:02 PM
#11
Fanatic Member
Re: [RESOLVED] How to make a form with round corners ?
hi Hack,
any component or reference required ?
quote:
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
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
thanks
cesin
-
Oct 4th, 2007, 12:15 PM
#12
Re: [RESOLVED] How to make a form with round corners ?
No...it should work as is.
-
Oct 4th, 2007, 12:54 PM
#13
Fanatic Member
Re: [RESOLVED] How to make a form with round corners ?
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
Code:
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
this code come with compile error
"Wrong number of argument or invalid property assignment" on bolt text
Regard,
cesin
-
Oct 4th, 2007, 01:00 PM
#14
Re: [RESOLVED] How to make a form with round corners ?
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
-
Oct 4th, 2007, 01:15 PM
#15
Fanatic Member
Re: [RESOLVED] How to make a form with round corners ?
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
-
Oct 4th, 2007, 01:41 PM
#16
Re: [RESOLVED] How to make a form with round corners ?
 Originally Posted by sigid
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...
Normally this is a must with any GDI Objects you create, this is one of the exceptions.
 Originally Posted by MSDN
After a successful call to SetWindowRgn, the system owns the region specified by the region handle hRgn. The system does not make a copy of the region. Thus, you should not make any further function calls with this region handle. In particular, do not delete this region handle. The system deletes the region handle when it no longer needed.
-
Oct 4th, 2007, 01:44 PM
#17
Re: [RESOLVED] How to make a form with round corners ?
 Originally Posted by ksuwanto8ksd
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
So change the Public to Private then...
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...
-
Oct 4th, 2007, 01:52 PM
#18
Fanatic Member
Re: [RESOLVED] How to make a form with round corners ?
oh ya great
thanks cvmichael
-
Oct 4th, 2007, 02:31 PM
#19
Addicted Member
Re: [RESOLVED] How to make a form with round corners ?
To Milk:
- Thanks for the link! "I was unaware of that!"
-
Oct 17th, 2013, 08:23 AM
#20
Member
Re: [RESOLVED] How to make a form with round corners ?
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
-
Oct 17th, 2013, 08:32 AM
#21
Re: [RESOLVED] How to make a form with round corners ?
-
Oct 17th, 2013, 08:26 PM
#22
Member
Re: [RESOLVED] How to make a form with round corners ?
 Originally Posted by Arnoutdv
Excellent
Thanks
:Ron
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|