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.

Recommended Answers

All 6 Replies

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

what do you mean?? image size?

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

wow thanks a lot :)

You're welcome. If that did the job, please remember to mark this solved. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.