Hefried's post on Rounded Corners

W

William Ryan

Herfried:

A while back you posted a really cool way to round the corners of a form. I
thought I had it saved, but if you have it handy, would you kindly post it?
TIA,

Bill

--
Cordially,

W.G. Ryan
(e-mail address removed)
www.devbuzz.com
www.knowdotnet.com
 
K

Ken Tucker [MVP]

Hi,

Here is how i do it.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim gp As GraphicsPath = New GraphicsPath

Dim radius As Single

radius = 25

gp.AddLine(radius, 0, Width - (radius * 2), 0)

gp.AddArc(Width - (radius * 2), 0, radius * 2, radius * 2, 270, 90)

gp.AddLine( Width, radius, Width, Height - (radius * 2))

gp.AddArc(Width - (radius * 2), Height - (radius * 2), radius * 2, radius *
2, 0, 90)

gp.AddLine(Width - (radius * 2), Height, radius, Height)

gp.AddArc(0, Height - (radius * 2), radius * 2, radius * 2, 90, 90)

gp.AddLine(0, Height - (radius * 2), 0, radius)

gp.AddArc(0, 0, radius * 2, radius * 2, 180, 90)



gp.CloseFigure()

Dim regRoundRect As New Region(gp)

Me.Region = regRoundRect

End Sub

Ken
 
W

William Ryan

Thanks Ken!
Ken Tucker said:
Hi,

Here is how i do it.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim gp As GraphicsPath = New GraphicsPath

Dim radius As Single

radius = 25

gp.AddLine(radius, 0, Width - (radius * 2), 0)

gp.AddArc(Width - (radius * 2), 0, radius * 2, radius * 2, 270, 90)

gp.AddLine( Width, radius, Width, Height - (radius * 2))

gp.AddArc(Width - (radius * 2), Height - (radius * 2), radius * 2, radius *
2, 0, 90)

gp.AddLine(Width - (radius * 2), Height, radius, Height)

gp.AddArc(0, Height - (radius * 2), radius * 2, radius * 2, 90, 90)

gp.AddLine(0, Height - (radius * 2), 0, radius)

gp.AddArc(0, 0, radius * 2, radius * 2, 180, 90)



gp.CloseFigure()

Dim regRoundRect As New Region(gp)

Me.Region = regRoundRect

End Sub

Ken
 
T

Tom Leylan

I can never resist messing with code... one might consider defining diameter
and avoid a number of identical multiplications

Dim radius As Single = 25
Dim diameter As Single = ( radius * 2 )

gp.AddLine(radius, 0, Width - diameter, 0)
gp.AddArc(Width - diameter, 0, diameter, diameter, 270, 90)

etc.
 
K

Ken Tucker [MVP]

Hi,

The graphicspath is in the system.drawing.drawing2d namespace. Add this
to the top of your file.
Imports System.Drawing.Drawing2D



Ken
 
T

Tom Spink

Just because you have that in your favourites..... ;-)))

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations

Herfried K. Wagner said:
* "Armin Zingler said:
A while back you posted a really cool way to round the corners of a
form. [...]
I'm not Herfried, but you might find the answer here:
http://groups.google.com/groups?as_...ugroup=microsoft.public.dotnet.*&as_scoring=d
<http://groups.google.com/[email protected]
l>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Is this NG Still working? 6
Writing in IL 11
Stupid Whidbey Questions 2
Using Params with an IN Statemet...Feedback 5
Who's a bigger Troll, Bailo or NoSpam? 6
OT: VB.NET Humor 5
MSMQ 6
OT- Just got back from MDC 2

Top