Round borders
Use this board to post your code snippets - tips and tricks
8 posts
Page 1 of 1
Easy code to create rounded borders around controls to make them look a bit nicer.
Manual code:
e.Graphics = Graphics instance
Color.Red = The colour of the border
Control.Location.X = Your control horizontal coordinates
Control.Location.Y = Your control vertical coordinates
Control.Width = Your control width
Control.Height = Your control height
5 = Radius of the curve
3 = Border thickness in pixels
Auto Code:
e.Graphics = Graphics instance
Color.Red = The colour of the border
ControlName = The name of your control
5 = Radius of the curve
3 = Border thickness in pixels
Can be used to make a nice UI cooll;
Manual code:
Code: Select all
To use just add the following in to your forms paint event: Public Sub RoundBorder(ByVal G As Graphics, ByVal BorderColour As Color, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, ByVal Radius As Single, ByVal Thickness As Single)
Dim GfXPath As GraphicsPath = New GraphicsPath()
Dim Border As New Pen(BorderColour, Thickness)
GfXPath.AddLine(X + Radius, Y, X + Width - (Radius * 2), Y)
GfXPath.AddArc(X + Width - (Radius * 2), Y, Radius * 2, Radius * 2, 270, 90)
GfXPath.AddLine(X + Width, Y + Radius, X + Width, Y + Height - (Radius * 2))
GfXPath.AddArc(X + Width - (Radius * 2), Y + Height - (Radius * 2), Radius * 2, Radius * 2, 0, 90)
GfXPath.AddLine(X + Width - (Radius * 2), Y + Height, X + Radius, Y + Height)
GfXPath.AddArc(X, Y + Height - (Radius * 2), Radius * 2, Radius * 2, 90, 90)
GfXPath.AddLine(X, Y + Height - (Radius * 2), X, Y + Radius)
GfXPath.AddArc(X, Y, Radius * 2, Radius * 2, 180, 90)
GfXPath.CloseFigure()
G.SmoothingMode = SmoothingMode.AntiAlias
G.DrawPath(Border, GfXPath)
GfXPath.Dispose()
End Sub
Code: Select all
Break downRoundBorder(e.Graphics, Color.Red, Control.Location.X, Control.Location.Y, Control.Width, Control.Height, 5, 3)
e.Graphics = Graphics instance
Color.Red = The colour of the border
Control.Location.X = Your control horizontal coordinates
Control.Location.Y = Your control vertical coordinates
Control.Width = Your control width
Control.Height = Your control height
5 = Radius of the curve
3 = Border thickness in pixels
Auto Code:
Code: Select all
Easier code without much fuss and again in the form paint event: Public Sub AutoRoundBorder(ByVal G As Graphics, ByVal BorderColour As Color, ByVal Who As Control, ByVal Radius As Single, ByVal Thickness As Single)
Dim GfXPath As GraphicsPath = New GraphicsPath()
Dim Border As New Pen(BorderColour, Thickness)
Dim X = Who.Location.X - Radius
Dim Y = Who.Location.Y - Radius
Dim Width = Who.Width + (Radius * 2) : Dim height = Who.Height + (Radius * 2)
GfXPath.AddLine(X + Radius, Y, X + Width - (Radius * 2), Y)
GfXPath.AddArc(X + Width - (Radius * 2), Y, Radius * 2, Radius * 2, 270, 90)
GfXPath.AddLine(X + Width, Y + Radius, X + Width, Y + height - (Radius * 2))
GfXPath.AddArc(X + Width - (Radius * 2), Y + height - (Radius * 2), Radius * 2, Radius * 2, 0, 90)
GfXPath.AddLine(X + Width - (Radius * 2), Y + height, X + Radius, Y + height)
GfXPath.AddArc(X, Y + height - (Radius * 2), Radius * 2, Radius * 2, 90, 90)
GfXPath.AddLine(X, Y + height - (Radius * 2), X, Y + Radius)
GfXPath.AddArc(X, Y, Radius * 2, Radius * 2, 180, 90)
GfXPath.CloseFigure()
G.SmoothingMode = SmoothingMode.AntiAlias
G.DrawPath(Border, GfXPath)
GfXPath.Dispose()
End Sub
Code: Select all
Break downAutoRoundBorder(e.Graphics, Color.Red, ControlName, 5, 3)
e.Graphics = Graphics instance
Color.Red = The colour of the border
ControlName = The name of your control
5 = Radius of the curve
3 = Border thickness in pixels
Can be used to make a nice UI cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
And that's why you use CSS:
Code: Select all
border-radius: 5px;
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo
This is VB..you Imbecile :lol:
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Overly complicated language...
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo
Yes but you can do more with VB then you can with CSS
But if you combine it with JS/PHP/Myself, you can do amazing stuff.. The main reason I quit views because of you wanted to distribute app, everyone needs windows with dot net framework..
than*
than*
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo
Think of CSS as VB.NET designer's properties window... now zoom out, add html, which is the "designer" view of .NET (where you add buttons etc.). Zoom out even more, add php and javascript to see how amazing and awesome it is.
OT: sorry for hijacking your awesome quick snip :P #CodenStuff
OT: sorry for hijacking your awesome quick snip :P #CodenStuff
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
Filip wrote:And that's why you use CSS:lmao; :lol: Ahhh that was funny :lol: lmao;
Code: Select allborder-radius: 5px;
jtlusco wrote:Yes but you can do more with VB then you can with CSSI'd have to disagree with you there, because VB is platform dependent.
8 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023