|
-
Jan 21st, 2005, 05:36 PM
#4
Re: Graphics - Rounded Corners
Ok, I got that to draw but how would I clear the square edges? I just need to
create a rectangle with the top two corners rounded and then fill it will a
gradient (I can do the fill part already). The background will be transparent
by default so when I draw the region and fill it the corners will be gone
already if the rectangle is rounded on top only.
This is the area that I need to convert to a region, I think, so it can be filled.
VB Code:
Function BorderRect() As Rectangle
Dim rec As Rectangle = Me.cmdClose.ClientRectangle
Return New Rectangle(1, 1, rec.Width - 3, rec.Height - 3)
End Function
Private Sub DrawRoundedButtons(ByVal g As Graphics, ByVal p As Pen, ByVal rec As Rectangle, ByVal size As Size)
Dim oldSmoothingMode As SmoothingMode = g.SmoothingMode
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
'Top line
g.DrawLine(p, rec.Left + size.Width \ 2, rec.Top, rec.Right - size.Width \ 2, rec.Top)
'Right top corner
g.DrawArc(p, rec.Right - size.Width, rec.Top, size.Width, size.Height, 270, 90)
'Right line
g.DrawLine(p, rec.Right, rec.Top + size.Height \ 2, rec.Right, rec.Bottom)
'Bottom line
g.DrawLine(p, rec.Right, rec.Bottom, rec.Left, rec.Bottom)
'Left line
g.DrawLine(p, rec.Left, rec.Bottom, rec.Left, rec.Top + size.Height \ 2)
'Left top corner
g.DrawArc(p, rec.Left, rec.Top, size.Width, size.Height, 180, 90)
g.SmoothingMode = oldSmoothingMode
End Sub
Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles cmdClose.Paint
DrawRoundedButtons(e.Graphics, New Pen(Color.Black), BorderRect, New Size(16, 16))
End Sub
Thanks
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
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
|