locked
Create my picture quiz

    Question

  • Hi everyone,

    I am after something :)

    I am creating a quiz called ultimate times tables which can be downloaded from the link below.

    I am using Visual studio ultimate 2012 .NET

    http://www.mastersworldofcomputing.com/quiz/timestableschart.php

    If you do not want to download you can just look at it as I have put a screenshot there as well.

    The problem I have is I want to create a quiz based on pictures, images. You can see from the screenshot above that I have an image of ducks. What I want is to be able to change that image when the correct answer has been given. So that the quiz moves on to question 2, is there anyone here that can start me off.

    Cheers Nige.
    • Edited by nigelsvision Tuesday, December 04, 2012 6:51 PM MORE DESCRIPTION
    Tuesday, December 04, 2012 6:48 PM

Answers

  • Hi nigelsvision,

    What the name of the button will not influence the behavior of button. If you want to swtich the picture in picturebox, you need to add code to the button.click event.

    Here is a small sample for switch the picture all the time (you need to change the path of the image).

    Public Class Form1
        'Use an integer record the one next to be dispalyed
        Dim i As Integer = 0
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Select Case i Mod 2
                Case 1
                    PictureBox1.Image = Image.FromFile("D:\pic\a.jpg")
                Case 0
                    PictureBox1.Image = Image.FromFile("D:\pic\b.jpg")
            End Select
            i = i + 1
        End Sub
    End Class

    Have a try.


    Mark Liu-lxf
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by nigelsvision Thursday, December 06, 2012 9:05 PM
    Thursday, December 06, 2012 3:04 AM

All replies

  • Hi nigelsvision,

    Welcome to the MSDN forum.

    I assume you have the source code of this application instead of just a setup files.

    When every time user click the button, you need to check whether the button is the right one. If yes, changed the picture in picturebox and changed the text in the button.

    So you can simply to do this by add the checking and exchanging code into the button click event.

    Hope this helps.


    Mark Liu-lxf
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 05, 2012 5:19 AM
  • Hi Mark Liu-lxf,

    You kind of answered my question as I am new to this I did not know where to look. Since your reply I have been scouring the net for examples on using picturebox. I still have a long way to go on getting this up and working but I don't mind working :)

    Anyway as I am taking my first steps I decided to just play about with picturebox so I have decided to create a simple picture viewer to start with. And use a button to change the image.

    So I created a new form, and inserted  PictureBox in my form I then went to properties of picturebox and imported 2 images in to my project. I created a button and then I inserted this code in to my button.

    Public Class Form1
    
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            PictureBox1.Image = My.Resources.background__2_
        End Sub
    End Class

    My form1 code looks like this

    Public Class Form1 Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click PictureBox1.Image = My.Resources.background__2_ End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class

    I changed the text on my button to "change" because I want to click on the button and have it change the

    image. But it does not work correctly.I click the button and it only changes the image once.

    I click the button a second time and nothing happens. Can you tell me why when I click the button

    a second time nothing happens.

    Thanks Nige

    • Edited by nigelsvision Wednesday, December 05, 2012 8:59 PM forgot my manners :)
    Wednesday, December 05, 2012 8:57 PM
  • Hi nigelsvision,

    What the name of the button will not influence the behavior of button. If you want to swtich the picture in picturebox, you need to add code to the button.click event.

    Here is a small sample for switch the picture all the time (you need to change the path of the image).

    Public Class Form1
        'Use an integer record the one next to be dispalyed
        Dim i As Integer = 0
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Select Case i Mod 2
                Case 1
                    PictureBox1.Image = Image.FromFile("D:\pic\a.jpg")
                Case 0
                    PictureBox1.Image = Image.FromFile("D:\pic\b.jpg")
            End Select
            i = i + 1
        End Sub
    End Class

    Have a try.


    Mark Liu-lxf
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by nigelsvision Thursday, December 06, 2012 9:05 PM
    Thursday, December 06, 2012 3:04 AM
  • Hi Mark,

    I marked this as answered because you did answer what I wanted regarding the picture switch. I tried your code and it worked, if you have the time would it be possible to explain the code to me. I would like to understand it more. I am more interested in the 2 things I have highlighted. Even though I have some code to work with I need to understand it so I can work with it. I am learning ll the time which is great :) but I have a thousand questions for this site :)

    Public Class Form1
        'Use an integer record the one next to be dispalyed
        Dim i As Integer = 0
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Select Case i Mod 2
                Case 1
                    PictureBox1.Image = Image.FromFile("D:\pic\a.jpg")
                Case 0
                    PictureBox1.Image = Image.FromFile("D:\pic\b.jpg")
            End Select
            i = i + 1
        End Sub

    End Class

    Thanks Nige.


    PS what I said earlier about changing the name of the button, I know it will not change behavior. I was just trying to describe what I had done :)
    • Edited by nigelsvision Thursday, December 06, 2012 9:25 PM manners
    Thursday, December 06, 2012 9:22 PM
  • Hi nigelsvision,

    If you want to understand my code well, you need to check the select… case statement firstly.

    Select...Case Statement (Visual Basic): http://msdn.microsoft.com/en-us/library/cy37t14y.aspx

    With this part of code, the picturebox will show picture a when “i” is an odd number, and show picture b when it is an even number.

    “i=i+1” will be invoked every time you click the button, so the integer “i” will be changed between odd and even which lead to picture in picturebox changed.

    Hope this helps. 


    Mark Liu-lxf
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 07, 2012 2:28 AM