C Sharp, having an issue with the spin button and displaying the images. See Pics using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Net.Http.Headers; using System.Web; namespace Slot_Machine { public partial class Form1 : Form { //Create a Random object Random rand = new Random(); //Create an image[] = the URL to the images. private Image[] images = new Image[] { Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Apple.bmp"), Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Banana.bmp"), Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Grapes.bmp"), Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Cherries.bmp"), Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Lemon.bmp"), Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Lime.bmp"), Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Orange.bmp"), Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Pear.bmp"), Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Strawbwerries.bmp") }; public Form1() { InitializeComponent(); } //Create a random method void RandomPicutes() { pictureBox1.Image = images[rand.Next(0, images.Length)]; pictureBox2.Image = images[rand.Next(0, images.Length)]; pictureBox3.Image = images[rand.Next(0, images.Length)]; } int FriutMactches() { int matches = 1; if (pictureBox1.Image == pictureBox2.Image) ++matches; if (pictureBox2.Image == pictureBox3.Image) ++matches; return matches; } void spinButton_Click(object sender, EventArgs e) { Random rand = new Random(); int index = rand.Next(images.Count); } } }
C Sharp, having an issue with the spin button and displaying the images. See Pics
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net.Http.Headers;
using System.Web;
namespace Slot_Machine
{
public partial class Form1 : Form
{
//Create a Random object
Random rand = new Random();
//Create an image[] = the URL to the images.
private Image[] images = new Image[]
{ Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Apple.bmp"),
Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Banana.bmp"),
Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Grapes.bmp"),
Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Cherries.bmp"),
Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Lemon.bmp"),
Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Lime.bmp"),
Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Orange.bmp"),
Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Pear.bmp"),
Image.FromFile("C:\\Users\\shari\\OneDrive\\Desktop\\Friut\\Strawbwerries.bmp")
};
public Form1()
{
InitializeComponent();
}
//Create a random method
void RandomPicutes()
{
pictureBox1.Image = images[rand.Next(0, images.Length)];
pictureBox2.Image = images[rand.Next(0, images.Length)];
pictureBox3.Image = images[rand.Next(0, images.Length)];
}
int FriutMactches()
{
int matches = 1;
if (pictureBox1.Image == pictureBox2.Image) ++matches;
if (pictureBox2.Image == pictureBox3.Image) ++matches;
return matches;
}
void spinButton_Click(object sender, EventArgs e)
{
Random rand = new Random();
int index = rand.Next(images.Count);
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps