|
|
 |
| Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
|
 |

June 1st, 2009, 09:27 PM
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Visual basic: Display pictures in matching pairs game
Hello I have made a 4x4 gird matching pairs game in visual basic. i have made a grid with of buttons for the user to click to show a hidden value. I have managed to get my buttons to display words and change colours when the user clicks them, but I can't get my buttons to display images when the user clicks them.
The total image pairs I want the buttons to display are a image of a apple, orange, star, heart, moon, triangle, sqaure and banana.
Can someone please edit my VB code so my buttons will display images instead of words?
Here is my current VB code for the matching Pairs game:
PublicClass Form1
Dim startstop AsInteger = 0
Dim pairwords AsNew ArrayList
Dim boxes(15) As Button
Dim firstclick, secondclick As Button
Dim isfirstclick AsBoolean = True
Dim diduwin AsInteger
Dim allowedtoclick AsBoolean = True
Dim timeleft AsInteger = 100
PrivateSub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click
Dim loopcounter AsInteger
Dim rand AsNew Random
tmnrtimeleft.Enabled = True
diduwin = 0
If startstop = 0 Then
btnstart.Text = "Stop"
startstop = 1
Else
btnstart.Text = "Start"
startstop = 0
EndIf
boxes(0) = Button1
boxes(1) = Button2
boxes(2) = Button3
boxes(3) = Button4
boxes(4) = Button5
boxes(5) = Button6
boxes(6) = Button7
boxes(7) = Button8
boxes(8) = Button9
boxes(9) = Button10
boxes(10) = Button11
boxes(11) = Button12
boxes(12) = Button13
boxes(13) = Button14
boxes(14) = Button15
boxes(15) = Button16
pairwords.Add("apple")
pairwords.Add("orange")
pairwords.Add("star")
pairwords.Add("heart")
pairwords.Add("moon")
pairwords.Add("triangle")
pairwords.Add("square")
pairwords.Add("banana")
pairwords.Add("apple")
pairwords.Add("orange")
pairwords.Add("star")
pairwords.Add("heart")
pairwords.Add("moon")
pairwords.Add("triangle")
pairwords.Add("square")
pairwords.Add("banana")
For i = 0 To 15 ' loops through each button
loopcounter = CInt(rand.Next(0, pairwords.Count)) 'random value limited by array list size
boxes(i).Tag = pairwords(loopcounter) ' add item from array list to button text
pairwords.RemoveAt(loopcounter) ' removes item from array list
Next
EndSub
PrivateSub tmrhide_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrhide.Tick
firstclick.Text = ""
secondclick.Text = ""
firstclick.FlatAppearance.BorderColor = Color.Black
secondclick.FlatAppearance.BorderColor = Color.Black
tmrhide.Enabled = False
allowedtoclick = True
EndSub
PrivateSub btnquit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnquit.Click
Me.Close()
EndSub
PrivateSub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click
If allowedtoclick = TrueThen
If isfirstclick = TrueThen
firstclick = sender
firstclick.Text = firstclick.Tag
isfirstclick = False
firstclick.FlatAppearance.BorderColor = Color.Yellow
Else
secondclick = sender
secondclick.Text = secondclick.Tag
isfirstclick = True
If firstclick.Tag = secondclick.Tag Then
firstclick.FlatAppearance.BorderColor = Color.Green
secondclick.FlatAppearance.BorderColor = Color.Green
diduwin = diduwin + 1
If diduwin = 8 Then
MessageBox.Show("Your a winner, you scum")
EndIf
Else
allowedtoclick = False
firstclick.FlatAppearance.BorderColor = Color.Red
secondclick.FlatAppearance.BorderColor = Color.Red
tmrhide.Enabled = True
EndIf
EndIf
EndIf
EndSub
PrivateSub tmnrtimeleft_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmnrtimeleft.Tick
timeleft = timeleft - 1
lbltimeleft.Text = timeleft
If timeleft = 0 Then
tmnrtimeleft.Enabled = False
timeleft = 100
EndIf
EndSub
EndClass
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |