![]() |
|
[Tutorial VB.Net] Making a Custom Button easily - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework) +--- Thread: [Tutorial VB.Net] Making a Custom Button easily (/Thread-Tutorial-VB-Net-Making-a-Custom-Button-easily) |
[Tutorial VB.Net] Making a Custom Button easily - Coder-san - 02-23-2011 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. ![]() 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.
RE: [Tutorial VB.Net] Making a Custom Button easily - White Charisma - 02-27-2011 good tut dude! ![]() thanks =D |