[Tutorial VB.Net] Making a Custom Button easily 02-23-2011, 10:32 AM
#1
Making a Custom Button easily
Hello everyone. Not so long ago, I shared with you my DrawProgress function.
Which can have MANY uses, from which I'm sharing one.
![[Image: 1d26029562.gif]](http://www.freeimagehosting.net/uploads/1d26029562.gif)
How to do that WITHOUT using any images?
We just need 1 Button (of course), 2 events for calling our function, and our same Function from before (which is here slightly modified).
Here is the Function, I call it this time PaintGradient.
Now we will use 2 events from our Button, MouseEnter and MouseLeave
That's it, you are done.
Hello everyone. Not so long ago, I shared with you my DrawProgress function.
Which can have MANY uses, from which I'm sharing one.
![[Image: 1d26029562.gif]](http://www.freeimagehosting.net/uploads/1d26029562.gif)
How to do that WITHOUT using any images?
We just need 1 Button (of course), 2 events for calling our function, and our same Function from before (which is here slightly modified).
Here is the Function, I call it this time PaintGradient.
Code:
Public Sub PaintGradient(ByVal aControl As Control, ByVal Color1 As Color, ByVal Color2 As Color, _
Optional ByVal mode As System.Drawing.Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.Vertical)
Dim bmp As New Bitmap(aControl.Width, aControl.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim Rect1 As New RectangleF(0, 0, aControl.Width, aControl.Height)
Dim lineGBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color1, Color2, mode)
g.FillRectangle(lineGBrush, Rect1)
aControl.BackgroundImage = bmp
g.Dispose()
End SubNow we will use 2 events from our Button, MouseEnter and MouseLeave
Code:
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
PaintGradient(Button1, Color.LightGoldenrodYellow, Color.YellowGreen)
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Button1.BackgroundImage = Nothing
End SubThat's it, you are done.
![[Image: rytwG00.png]](http://i.imgur.com/rytwG00.png)
Redcat Revolution!

![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
