|
-
Oct 25th, 2010, 03:24 PM
#1
Thread Starter
Addicted Member
Rounded Corners
First of all, I can't take full credit for this, as I borrowed this myself from somewhere, but can't remember where now.
Anywho, I've noticed quite a many request in this and other forums to figure out how to round corners of an object.
So i'm posting an Official Function that makes it very Easy.
Simply Copy & Paste the following function into your form somewhere
Round It Code:
Private Sub makeRound(ByVal vObject As Object)
Dim p As New Drawing2D.GraphicsPath()
p.StartFigure()
p.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
p.AddLine(20, 0, vObject.Width - 20, 0)
p.AddArc(New Rectangle(vObject.Width - 20, 0, 20, 20), -90, 90)
p.AddLine(vObject.Width, 20, vObject.Width, vObject.Height - 20)
p.AddArc(New Rectangle(vObject.Width - 20, vObject.Height - 20, 20, 20), 0, 90)
p.AddLine(vObject.Width - 20, vObject.Height, 20, vObject.Height)
p.AddArc(New Rectangle(0, vObject.Height - 20, 20, 20), 90, 90)
p.CloseFigure()
vObject.Region = New Region(p)
End Sub
For more of a rounded curve try replacing all of the "20"s with "40"
To make use on almost any object in a form simply:
Use It Code:
makeRound(yourObject)
' Like
makeRound(TreeView1)
Tada!
-
Oct 26th, 2010, 09:17 PM
#2
Lively Member
Re: Rounded Corners
Option Strict-compliant, safer, and more customizable version:
Code:
Private Sub MakeRound(ByVal c As Control, Optional ByVal radius As Integer = 20)
Dim p As New Drawing2D.GraphicsPath()
p.AddArc(New Rectangle(0, 0, radius, radius), 180, 90)
p.AddLine(20, 0, vObject.Width - 20, 0)
p.AddArc(New Rectangle(vObject.Width - radius, 0, radius, radius), -90, 90)
p.AddLine(vObject.Width, 20, vObject.Width, vObject.Height - radius)
p.AddArc(New Rectangle(vObject.Width - radius, vObject.Height - radius, radius, radius), 0, 90)
p.AddLine(vObject.Width - 20, vObject.Height, 20, vObject.Height)
p.AddArc(New Rectangle(0, vObject.Height - 20, 20, 20), 90, 90)
p.CloseFigure()
c.Region = New Region(p)
End Sub
P.S. radius should actually be diameter.
-
Oct 28th, 2010, 02:45 AM
#3
Re: Rounded Corners
The lines with AddLine are unnecessary. Since it is all one figure, the path will extend from the end point of one arc to the next. BB
-
Oct 28th, 2010, 11:47 AM
#4
Thread Starter
Addicted Member
Re: Rounded Corners
 Originally Posted by boops boops
The lines with AddLine are unnecessary. Since it is all one figure, the path will extend from the end point of one arc to the next. BB
Lol, I kinda figured as much, just figured I'd share the easy recipe I've been using with others questioning how to do it. I'll maybe break it down and explain it as well as perfect it later, right now, I'm extremely overworked and underpayed and have to get back to that, lol.
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
|