rounded button with gradient color in

hi,
can anyone tell me how to do rounded button with gradient color inside?
OM.
[97 byte] By [omrao] at [2007-11-20 11:45:56]
# 1 Re: rounded button with gradient color in
I was inclined to post a VB 6 solution to this problem, because you haven't specified which version of VB you are using.

That aside, I felt that this is quite an interesting topic, so I worked something out.
Add the following to your button's Paint event. ( in this example, I used Button1_Paint )

Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint

Dim X1 As Integer, Y1 As Integer, Width As Single, Height As Single 'Left, Top, Width, Height
Dim RoundRadius As Integer, LineColor As Color 'corner radius, line color

Try
X1 = Button1.Left 'Left
Y1 = Button1.Top 'Top
Width = Button1.Width 'Width
Height = Button1.Height 'Height
RoundRadius = 15 'Radius
LineColor = Color.Green 'Line

Dim gr As System.Drawing.Graphics 'Graphics object

gr = Graphics.FromHwnd(ActiveForm.Handle) 'Where

Dim Pen As New System.Drawing.Pen(LineColor) 'Drawing pen

'Draw rect
Dim myPath As System.Drawing.Drawing2D.GraphicsPath = New System.Drawing.Drawing2D.GraphicsPath
If RoundRadius > Width / 2 OrElse RoundRadius > Height / 2 Then RoundRadius = Height / 2

myPath.StartFigure()

myPath.AddArc(X1, Y1, RoundRadius * 2, RoundRadius * 2, 180, 90)
myPath.AddArc(X1 + Width - RoundRadius * 2, Y1, RoundRadius * 2, RoundRadius * 2, 270, 90)
myPath.AddArc(X1 + Width - RoundRadius * 2, Y1 + Height - RoundRadius * 2, RoundRadius * 2, RoundRadius * 2, 0, 90)
myPath.AddArc(X1, Y1 + Height - RoundRadius * 2, RoundRadius * 2, RoundRadius * 2, 90, 90)
myPath.CloseFigure()

'Button background
Dim brBackground As New System.Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, System.Drawing.Color.FromArgb(255, 0, 0), Color.FromArgb(0, 0, 255), System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
gr.DrawPath(Pen, myPath)
e.Graphics.FillRectangle(brBackground, e.ClipRectangle)

Button1.Region = New Region(myPath) 'Apply
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

This, creates a rounded rectangular button, with a gradient fill inside.

Right, I handed this code to you on a silver platter, now, the onus is on you to do some reasearch on the follwing :
Regions
GraphicsPath
LinearGradientBrush
FromArgb
System.Drawing
System.Drawing.Drawing2d
Object events ( for example, the Paint event )
System.Drawing.Graphics
Drawing shapes with GDI+

... Else, the above code will be completely meaningless, and a wasted effort which will just be copied and pasted till infinity ...
HanneSThEGreaT at 2007-11-10 3:08:13 >