As a precursor: I am very new to C# and yes this is homework.
I am working on a program that stores 52 card .bmp's in an array, randomizes which cards appear in the 5 picture boxes, and then when the user clicks on the card, it displays the name of the card. I'm stuck on the last part of this. Thanks in advance!
public partial class cardIdentifier : Form
{
public cardIdentifier()
{
InitializeComponent();
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox5.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Image = deck[new Random().Next(0, deck.Length)];
pictureBox2.Image = deck[new Random(+1).Next(0, deck.Length)];
pictureBox3.Image = deck[new Random(+5).Next(0, deck.Length)];
pictureBox4.Image = deck[new Random(+10).Next(0, deck.Length)];
pictureBox5.Image = deck[new Random(-7).Next(0, deck.Length)];
}
//Creating and adding images to the array
Image[] deck = new Image[52] { Card_Identify.Properties.Resources.clubAce, Card_Identify.Properties.Resources.clubTwo, Card_Identify.Properties.Resources.clubThree, Card_Identify.Properties.Resources.clubFour, Card_Identify.Properties.Resources.clubFive , Card_Identify.Properties.Resources.clubSix , Card_Identify.Properties.Resources.clubSeven , Card_Identify.Properties.Resources.clubEight , Card_Identify.Properties.Resources.clubNine , Card_Identify.Properties.Resources.clubTen , Card_Identify.Properties.Resources.clubJack , Card_Identify.Properties.Resources.clubQueen , Card_Identify.Properties.Resources.clubKing , Card_Identify.Properties.Resources.spadeAce , Card_Identify.Properties.Resources.spadeTwo , Card_Identify.Properties.Resources.spadeThree , Card_Identify.Properties.Resources.spadeFour , Card_Identify.Properties.Resources.spadeFive , Card_Identify.Properties.Resources.spadeSix , Card_Identify.Properties.Resources.spadeSeven , Card_Identify.Properties.Resources.spadeEight , Card_Identify.Properties.Resources.spadeNine , Card_Identify.Properties.Resources.spadeTen , Card_Identify.Properties.Resources.spadeJack , Card_Identify.Properties.Resources.spadeQueen , Card_Identify.Properties.Resources.spadeKing , Card_Identify.Properties.Resources.heartAce , Card_Identify.Properties.Resources.heartTwo , Card_Identify.Properties.Resources.heartThree , Card_Identify.Properties.Resources.heartFour , Card_Identify.Properties.Resources.heartFive , Card_Identify.Properties.Resources.heartSix , Card_Identify.Properties.Resources.heartSeven , Card_Identify.Properties.Resources.heartEight , Card_Identify.Properties.Resources.heartNine , Card_Identify.Properties.Resources.heartTen , Card_Identify.Properties.Resources.heartJack , Card_Identify.Properties.Resources.heartQueen , Card_Identify.Properties.Resources.heartKing , Card_Identify.Properties.Resources.diamondAce , Card_Identify.Properties.Resources.diamondTwo , Card_Identify.Properties.Resources.diamondThree , Card_Identify.Properties.Resources.diamondFour , Card_Identify.Properties.Resources.diamondFive , Card_Identify.Properties.Resources.diamondSix , Card_Identify.Properties.Resources.diamondSeven , Card_Identify.Properties.Resources.diamondEight , Card_Identify.Properties.Resources.diamondNine , Card_Identify.Properties.Resources.diamondTen , Card_Identify.Properties.Resources.diamondJack , Card_Identify.Properties.Resources.diamondQueen , Card_Identify.Properties.Resources.diamondKing };
//Changes the card shown in picture box
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = deck[new Random().Next(0, deck.Length)];
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox2.Image = deck[new Random().Next(0, deck.Length)];
}
private void button3_Click(object sender, EventArgs e)
{
pictureBox3.Image = deck[new Random().Next(0, deck.Length)];
}
private void button4_Click(object sender, EventArgs e)
{
pictureBox4.Image = deck[new Random().Next(0, deck.Length)];
}
private void button5_Click(object sender, EventArgs e)
{
pictureBox5.Image = deck[new Random().Next(0, deck.Length)];
}
public void pictureBoxes_Click(object sender, EventArgs e)
{
//THIS IS WHERE IM STUCK, NEED TO DISPLAY NAME OF CARD WHEN ITS CLICKED!
}
}
}
Aucun commentaire:
Enregistrer un commentaire