Public Class Close
    Inherits Windows.Forms.Button

    Public Sub New()
        Me.Size = New System.Drawing.Point(25, 25)
        Me.FlatStyle = Windows.Forms.FlatStyle.Flat
        Me.BackgroundImage = My.Resources.CloseNormal
        Me.BackgroundImageLayout = Windows.Forms.ImageLayout.Stretch
        Me.BackColor = Drawing.Color.Transparent
        Me.Font = New System.Drawing.Font("Calibri", 10, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = Drawing.Color.Black
        Me.FlatAppearance.BorderColor = Drawing.Color.DeepSkyBlue
        Me.FlatAppearance.MouseDownBackColor = Drawing.Color.Transparent
        Me.FlatAppearance.MouseOverBackColor = Drawing.Color.Transparent
        Me.FlatAppearance.BorderSize = 0
    End Sub

    Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        Me.BackgroundImage = My.Resources.ClosePress
    End Sub

    Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
        Me.BackgroundImage = My.Resources.CloseNormal
    End Sub

    Private Sub Button1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
        Me.BackgroundImage = My.Resources.CloseHigh
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
        Me.BackgroundImage = My.Resources.CloseNormal
    End Sub
End Class

I want to replace a button with another yet different button (eg. Maximise with RestoreDown). How can I do this?
The code above is for making a custom button.

5 Years
Discussion Span
Last Post by tinstaafl

I want to replace a button with another yet different button (eg. Maximise with RestoreDown)

What exactly do you mean by this?


you know how forms (with borders) when "Maximise" is clicked it will change to "Restore" (the image changes)
how can i do this? thanks


I'm still not sure I understand, but I'll take a stab at it.

It appears you want to make a new button that will toggle the image from one to another everytime it is clicked. You don't really need a custom button. A boolean variable and a click event handler on a normal button will do the job.

Something like this:

    Dim Image1 As Bitmap = New Bitmap(My.Resources.Image1)
    Dim Image2 As Bitmap = New Bitmap(My.Resources.Image2)
    Dim Clicked As Boolean = False
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Select Case Clicked
            Case True
                Button3.Image = Image1
            Case False
                Button3.Image = Image2
        End Select
        Clicked = Not Clicked
    End Sub

Edited by tinstaafl

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.