Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 1st, 2009, 08:27 PM
Registered User
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
End
Class





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a basic program to play online game glcn74 Pro Visual Basic 2005 1 June 10th, 2007 07:25 PM
Display many pictures NBM Java GUI 0 September 3rd, 2006 06:54 AM
FTP in Visual Studio 2005 Pro (Visual Basic) shoopes VB How-To 1 June 29th, 2006 02:08 PM
Query to display non matching records. AJ Access VBA 1 April 7th, 2005 05:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.