Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy aren't the buttons in my C# Application working?
    primarykey
    data
    text
    <p>I am doing this lab out of a book on my own, and I made an application in which sharks are racing. There is a radio button that should update a label on the right dynamically, as well as a button that actually starts the race. Everything used to work and then I renamed a few things, and now nothing works.</p> <p>Screenshot of application:</p> <p><a href="http://cl.ly/f08f4e22761464e0c2f3/content" rel="nofollow noreferrer">image http://cl.ly/f08f4e22761464e0c2f3/content</a></p> <p>Form Class:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace project1 { public partial class Game : Form { private Shark[] sharks; private Guy[] guys; private Guy selectedGuy; public Game() { InitializeComponent(); Random moreRandom = new Random(); int start = myTrack.Location.X; int finish = myTrack.Width - 65; sharks = new Shark[4] { new Shark() {myRandom = moreRandom, myPictureBox = myShark1, myPBStart = start, trackLength = finish}, new Shark() {myRandom = moreRandom, myPictureBox = myShark2, myPBStart = start, trackLength = finish}, new Shark() {myRandom = moreRandom, myPictureBox = myShark3, myPBStart = start, trackLength = finish}, new Shark() {myRandom = moreRandom, myPictureBox = myShark4, myPBStart = start, trackLength = finish} }; guys = new Guy[3] { new Guy() {myName="Joe", cash=50, myRadioButton=rbGuy1, myLabel=labelBet1}, new Guy() {myName="Bob", cash=75, myRadioButton=rbGuy2, myLabel=labelBet2}, new Guy() {myName="Al", cash=45, myRadioButton=rbGuy3, myLabel=labelBet3} }; selectedGuy = guys[0]; rbGuy1.Tag = guys[0]; rbGuy2.Tag = guys[1]; rbGuy3.Tag = guys[2]; updateGui(); } private void myChanged(object sender, EventArgs e) { selectedGuy = getSelectedGuy(sender); betterLabel.Text = selectedGuy.myName; } private void betAmountValue(object sender, EventArgs e) { updateMin(); } private void Bet_Click(object sender, EventArgs e) { int bet = (int) betAmount.Value; int myFish = (int) sharkNumber.Value; selectedGuy.placeBet(bet, myFish); updateGui(); } private void raceBtn_Click(object sender, EventArgs e) { betBtn.Enabled = false; bool noWinner = true; while(noWinner) { for (int dogFish = 0; dogFish &lt; sharks.Length; dogFish++) { Application.DoEvents(); if(sharks[dogFish].Swim()) { showWinner(dogFish); collectBets(dogFish); noWinner = false; } } } updateGui(); betBtn.Enabled = true; } private void showWinner(int fish) { MessageBox.Show(string.Format("Winner Winner People Dinner! \nShark {0} won!", fish + 1)); } private void collectBets(int fish) { for (int guyNumber = 0; guyNumber &lt; guys.Length; guyNumber++) { guys[guyNumber].collect(fish + 1); guys[guyNumber].resetBet(); } } private void updateMin() { minBetLabel.Text = string.Format("Minimum bet: 5 bucks", betAmount.Value); } private Guy getSelectedGuy(object sender) { RadioButton rb = (RadioButton)sender; return (Guy)rb.Tag; } private void updateGui() { for (int guyNumber = 0; guyNumber &lt; guys.Length; guyNumber++) { guys[guyNumber].updateLabels(); } for (int fish = 0; fish &lt; sharks.Length; fish++) { sharks[fish].startPosition(); } updateMin(); } } } </code></pre> <p>Shark Class:</p> <pre><code>using System; using System.Drawing; using System.Threading; using System.Windows.Forms; namespace project1 { public class Shark { public int myPBStart; // Where the PictureBox starts public int trackLength; // How long the racetrack is public PictureBox myPictureBox = null; // The PictureBox object public int location = 0; // My location on the racetrack public Random myRandom; // An instance of Random public Shark() { location = 0; myPictureBox = new PictureBox(); myRandom = new Random(); trackLength = 100; myPBStart = 0; } public bool Swim() { int distance = myRandom.Next(1, 4); location += distance; movePB(distance); return location &gt; trackLength; } private void movePB(int distance) { Point p = myPictureBox.Location; p.X += distance; myPictureBox.Location = p; } public void startPosition() { location = myPBStart; Point p = myPictureBox.Location; p.X = location; myPictureBox.Location = p; } } } </code></pre> <p>I can supply more resources if needed, but this is the main gist of it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload