Hi everyone,
So OK basically I need to create animated button with three pictures (optional) which will represent the button as active, passive and activated.
So the task wasn't very hard until my teacher added another thing: The user to be able to choose which picture to use.

So my questions are these:
First: Passive is when the button is not clicked, activated is when it is clicked, but what is active? When you rollover on it? Any idea?
Second: How it is possible to choose a picture for every state of the button? Combo box? Radio buttons? Any idea what can I use?

Thanks in advance!

Member Avatar


Heres an example that may help

This lets the user choose their own image for each button state

Public Class Form1
    Private ButtonImageList As ImageList

    Private Enum ButtonState
    End Enum

    Private Class ImageSelector : Inherits Form
        Private _ImageList As ImageList
        Private picActive As PictureBox
        Private picActivated As PictureBox
        Private picPassive As PictureBox
        Private lblActive As Label
        Private lblActivated As Label
        Private lblPassive As Label
        Private fpnlSelector As FlowLayoutPanel

        Property ImageList() As ImageList
                Return _ImageList
            End Get
            Set(ByVal value As ImageList)
                If value Is Nothing Then value = New ImageList

                _ImageList = value

                If _ImageList.Images.ContainsKey(ButtonState.Activated.ToString) Then
                    picActivated.Image = _ImageList.Images(ButtonState.Activated.ToString)
                End If

                If _ImageList.Images.ContainsKey(ButtonState.Active.ToString) Then
                    picActive.Image = _ImageList.Images(ButtonState.Active.ToString)
                End If

                If _ImageList.Images.ContainsKey(ButtonState.Passive.ToString) Then
                    picPassive.Image = _ImageList.Images(ButtonState.Passive.ToString)
                End If
            End Set

        End Property

        Sub New()
            picActive = New PictureBox
            picActivated = New PictureBox
            picPassive = New PictureBox
            lblActive = New Label
            lblActivated = New Label
            lblPassive = New Label
            fpnlSelector = New FlowLayoutPanel

            picActivated.BorderStyle = BorderStyle.Fixed3D
            picActivated.Size = New Size(50, 50)
            picActivated.Margin = New Padding(5, 0, 10, 5)
            picActivated.Name = ButtonState.Activated.ToString
            picActivated.Cursor = Cursors.Hand
            picActivated.SizeMode = PictureBoxSizeMode.Zoom
            AddHandler picActivated.Click, AddressOf PicButtonState_Clicked

            picActive.BorderStyle = BorderStyle.Fixed3D
            picActive.Size = New Size(50, 50)
            picActive.Margin = New Padding(5, 0, 10, 5)
            picActive.Name = ButtonState.Active.ToString
            picActive.Cursor = Cursors.Hand
            picActive.SizeMode = PictureBoxSizeMode.Zoom
            AddHandler picActive.Click, AddressOf PicButtonState_Clicked

            picPassive.BorderStyle = BorderStyle.Fixed3D
            picPassive.Size = New Size(50, 50)
            picPassive.Margin = New Padding(5, 0, 10, 5)
            picPassive.Name = ButtonState.Passive.ToString
            picPassive.Cursor = Cursors.Hand
            picPassive.SizeMode = PictureBoxSizeMode.Zoom
            AddHandler picPassive.Click, AddressOf PicButtonState_Clicked

            lblActivated.Margin = New Padding(5, 0, 5, 0)
            lblActivated.AutoSize = True
            lblActivated.Text = "Activated"

            lblActive.Margin = New Padding(5, 0, 5, 0)
            lblActive.AutoSize = True
            lblActive.Text = "Active"

            lblPassive.Margin = New Padding(5, 0, 5, 0)
            lblPassive.AutoSize = True
            lblPassive.Text = "Passive"

            fpnlSelector.Dock = DockStyle.Fill
            fpnlSelector.AutoScroll = True
            fpnlSelector.FlowDirection = FlowDirection.TopDown
            fpnlSelector.WrapContents = False


            Me.Size = New Size(250, 350)
            Me.MinimizeBox = False
            Me.MaximizeBox = False
            Me.ShowIcon = False
            Me.Text = "Select Button State Images"


        End Sub

        Private Sub PicButtonState_Clicked(ByVal sender As Object, ByVal e As EventArgs)
            If sender Is Nothing OrElse Not TypeOf sender Is PictureBox Then Exit Sub

            Dim ofd As New OpenFileDialog
            ofd.Filter = "Image Files | *.jpg; *.png; *.gif; *.bmp"
            ofd.FilterIndex = 0

            If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                With CType(sender, PictureBox)
                    If fpnlSelector.Controls.ContainsKey(.Name) Then
                        .Image = New Bitmap(ofd.FileName)
                    End If

                    If ImageList.Images.ContainsKey(.Name) Then
                    End If

                    ImageList.Images.Add(.Name, .Image)
                End With
            End If


        End Sub

    End Class

    Sub New()
        ' This call is required by the Windows Form Designer.

        ' Add any initialization after the InitializeComponent() call.
        ButtonImageList = New ImageList
        ButtonImageList.ImageSize = btnImages.Size
        ButtonImageList.ColorDepth = ColorDepth.Depth32Bit

        btnImages.ImageList = ButtonImageList

    End Sub

    Private Sub btnImages_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnImages.MouseDown
        btnImages.ImageKey = ButtonState.Activated.ToString
    End Sub

    Private Sub btnImages_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnImages.MouseEnter
        btnImages.ImageKey = ButtonState.Active.ToString
    End Sub

    Private Sub btnImages_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnImages.MouseLeave
        btnImages.ImageKey = ButtonState.Passive.ToString
    End Sub

    Private Sub btnImages_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnImages.MouseUp
        btnImages.ImageKey = ButtonState.Active.ToString
    End Sub

    Private Sub btnChooseImages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChooseImages.Click
        Dim frmSelect As New ImageSelector
        frmSelect.ImageList = ButtonImageList
        btnChooseImages.ImageKey = ButtonState.Passive.ToString
    End Sub
End Class

Thank you very much! Well I will try it and I'll tell you how the button is going.
THANK YOU again.

where the heck do you find these EXAMPLES lol i never find such good ones