locked
Adding a button to show a picture when clicked, and clear a picture when clicked RRS feed

  • Question

  • Right now I have a program that displays a picture when clicked.

    I want to program the one button to show and clear the picture.

    Thanks in advance.

    Friday, May 24, 2013 3:44 PM

Answers

  • Hi

    Use a Static Boolean variable inside the button click event (lets call it Toggle). 

    Private Sub Button1_Click(........ etc)

    Static Toggle as boolean = False

    If Toggle then

    Code to Clear picture

    Else

    Code to show picture

    End If

    Toggle = Not Toggle

    End Sub


    Regards Les, Livingston, Scotland

    • Marked as answer by bsbdm Friday, May 24, 2013 5:24 PM
    Friday, May 24, 2013 4:47 PM

All replies

  • You could do something like this.

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If PictureBox1.Image Is Nothing Then
                PictureBox1.Image = Image.FromFile("C:\test\mypicture.jpg")
            Else
                PictureBox1.Image = Nothing
            End If
        End Sub
    

    Friday, May 24, 2013 4:47 PM
  • Hi

    Use a Static Boolean variable inside the button click event (lets call it Toggle). 

    Private Sub Button1_Click(........ etc)

    Static Toggle as boolean = False

    If Toggle then

    Code to Clear picture

    Else

    Code to show picture

    End If

    Toggle = Not Toggle

    End Sub


    Regards Les, Livingston, Scotland

    • Marked as answer by bsbdm Friday, May 24, 2013 5:24 PM
    Friday, May 24, 2013 4:47 PM