How Do I Get Two Image RRS feed

All replies

  • The button has a backgroundimage property

    TheButton.Backgroundimage = image.fromfile(path)


    • Proposed as answer by leshay Tuesday, March 20, 2018 7:06 PM
    Tuesday, March 20, 2018 6:58 PM
  • How Do I Make A Off Switch With The Button And Images

    Do you mean an On/Off switch?  You can make a check box work like a button with an image.  See:

        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
            CheckBox1.AutoSize = False
            CheckBox1.Text = ""
            CheckBox1.ImageList = New ImageList
            CheckBox1.Appearance = Appearance.Button
        End Sub
        Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
            If CheckBox1.Checked Then
                CheckBox1.ImageIndex = 0
                CheckBox1.ImageIndex = 1
            End If
        End Sub
    The properties can be set in the designer instead of the shown event.

    Tuesday, March 20, 2018 9:50 PM
  • You should show what you have done and be specific.

    Ask a specific question about something you don't understand. If this is for school you should say that.

    I made an example similar to Acamar's using a checkbox that draws the images.

    Public Class Form3
        Private bmps As New List(Of Bitmap)
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            CheckBox1.Appearance = Appearance.Button
            'make the bitmap images and add to the list of bitmaps
            Dim bmp As Bitmap
            bmp = GetBitmap(100, 50, Color.Red, Color.AntiqueWhite, "On")
            bmps.Add(CType(bmp.Clone, Bitmap))
            bmp = GetBitmap(100, 50, Color.Green, Color.AntiqueWhite, "Off")
            bmps.Add(CType(bmp.Clone, Bitmap))
            CheckBox1.Text = ""
            CheckBox1.Checked = True
        End Sub
        Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
            If CheckBox1.Checked Then
                CheckBox1.Image = bmps(0)           'on
                CheckBox1.Image = bmps(1)           'off
            End If
        End Sub
        Private Function GetBitmap(w As Integer, h As Integer, bgclr As Color, fclr As Color, txt As String) As Bitmap
            Using bmp As New Bitmap(w, h),
                g As Graphics = Graphics.FromImage(bmp),
                f As New Font("tahoma", 18, FontStyle.Bold)
                g.DrawString(txt, f, New SolidBrush(fclr), 20, 10)
                GetBitmap = CType(bmp.Clone, Bitmap)
            End Using
        End Function
    End Class

    Tuesday, March 20, 2018 10:06 PM
  • Hi DJ103,

    You can do like this:

     Dim listimage As New List(Of Image)
        Private Sub FrmToolStrip_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Button2.Image = listimage(0)
        End Sub
     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            If Button2.Image Is listimage(0) Then
                Button2.Image = listimage(1)
                Button2.Image = listimage(0)
            End If
        End Sub

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, March 21, 2018 7:44 AM