Creaintg VB.NET Buttons with Mettalic or Gradient Effect
Posted on 2008-02-07
I have the need to create VB.NET form buttons with a Gradient effect. I have located some code to do this with the Form itself and that works perfectly, however when I try it with the Button within that form it does not work as expected. The buttons either have the gradient with no Text (the gradient disappears and the Text re-appears on Button Mouse Hover or Click) or no gradient at all. The codes is as follows:
Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
'Create the Metallic gradient affect on Button1 ....
Dim g As Graphics = Button1.CreateGraphics
Dim intWidth As Integer = Button1.Width - 3
Dim intHeight As Integer = Button1.Height - 3
Dim lgBrush As New LinearGradientBrush(New Point(1, 1), New Point(intWidth, intHeight), _
Color.White, Color.FromArgb(190, 190, 190))
g.FillRectangle(lgBrush, 0, 0, intWidth, intHeight)
The same code as I said works perfectly with the forms itself but not the buttons and the results on the buttons vary depending on the Flatstyle setting. Can anyone help with some advice on what is wrong OR provide some code that might do the job?