p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

Free Code from Wrox
Go Back   p2p.wrox.com Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
I forgot my password
Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 .
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 1st, 2009, 09:27 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 08:25 PM
Display many pictures NBM Java GUI 0 September 3rd, 2006 07:54 AM
Display many pictures NBM BOOK: Professional Java Native Interfaces with SWT/JFace 0 September 3rd, 2006 07:50 AM
FTP in Visual Studio 2005 Pro (Visual Basic) shoopes VB How-To 1 June 29th, 2006 03:08 PM
Query to display non matching records. AJ Access VBA 1 April 7th, 2005 06:05 PM



All times are GMT -4. The time now is 02:48 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc