Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[TUT]Making a Custom Button easily[TUT]

[IMG]http://www.[censored].net/uploads/1d26029562.gif[/IMG]
ow 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 Sub

Now 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 Sub

That's it, you are done. :lol:
(Apr 7, 2011 01:49 PM)Vertu Wrote:  ow to do that WITHOUT using any images?

Technically this is using images. Hence the bitmap.
why not
PHP Code

<?php 
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
  PaintGradient
(Button1, Color.LightGoldenrodYellow, Color.Green)
    
End Sub
    
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  PaintGradient
(Button1, Color.LightGoldenrodYellow, Color.Yellow)
    
End Sub 
(Apr 7, 2011 01:52 PM)Cody8295 Wrote:  Technically this is using images. Hence the bitmap.
Ok,just i you dint need to load from resources

@no1me

That works too 🤗
(Apr 7, 2011 02:20 PM)Vertu Wrote:  Ok,just i you dint need to load from resources

@no1me

That works too 🤗

You don't need to if you use and imagelist with local images.

This is nice, thank you no1me for the code modification, making it simpler and such.
I love this. I hope you make more tutorials like how to make custom background, progress bars, etc.

And can't you do:

Code
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
  Button1.BackColor = Color.LightGoldenrodYellow
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
  Button1.BackColor = Color.Empty
    End Sub
(Apr 7, 2011 04:33 PM)Marketplace Wrote:  I love this. I hope you make more tutorials like how to make custom background, progress bars, etc.

And can't you do:

Code
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
  Button1.BackColor = Color.LightGoldenrodYellow
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
  Button1.BackColor = Color.Empty
    End Sub

All your code is doing is applying a single color. The other codes are filling with a gradient.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by LeonieHackPetaBytes2Jan 23, 2019 05:10 PM 1 227 Jan 23, 2019 05:10 PM
Last Post: 0xDEAD10CC
[C] by aeiroJul 22, 2018 10:43 AM 4 213 Jul 22, 2018 10:43 AM
Last Post: aeiro
[.NET] by hfTP54Feb 3, 2017 05:12 AM 1 294 Feb 3, 2017 05:12 AM
Last Post: SIM-1847363