Click to See Complete Forum and Search --> : How do I make my controls appear gradient


Alex Kobe
September 11th, 2005, 12:45 PM
Anyone who can help me how to make my button control appear gradient?

I was able to do it on a form using LinearGradientBrush class but I can't do it in my button control (when i use the same class on button1_Paint event).

btw, Im new to visual basic .net

jhammer
September 11th, 2005, 04:47 PM
Create a new class.
Inherit the class from Button class (System.Windows.Forms namespace).
Override the OnPaint method of Button:

Private Overrides Sub OnPaint(e As PaintEventArgs)
Dim angle As Float = ... ' Pick an angle for the gradient
Dim b As Brush = New LinearGradientBrush(e.ClipRectangle, Color.White, Color.Black, angle )
e.Graphics.FillRectangle(b, e.ClipRectangle)
End Sub


You can change the angle, and the two colors.

Rebuild the solotion and the button will be added to the TooloBox under My User Controls.
Drag it to your forms.