winforms - Textbox wont update -


So I'm creating a basic yahtzee program IC #, and try to create a real GUI and not only use the console.

. Although I have a problem with the text box. When I roll the dice, I want to display the rolled number of the text box. Now it does not show anything I use two squares, one for a real program and one to handle a guy. This is the yahtzee class:

  using the system; Using System.Collections.Generic; Using System.Linq; System usage threading. Task; Using System.Windows.Forms; Nameshot Hantzhi {class YahtzeeScorer {random rndm = new random (); Form 1 Guai = New Form 1 (); String die 1, dis2, dis3, dis 4, dis5; Public zero rolledis () {string a = console.readline (); This.dice1 = rndm.ext (1, 7) .ostring (); This.gui.tbDice_SetText (this.dice1); } Fixed zero main (string [] args) {Application.EnableVisualStyles (); Application.SetCompatibleTextRenderingDefault (wrong); YahtzeeScorer ys = New YahtzeeScorer (); Application.Run (ys.gui); Ys.rollDice (); Console.light line ("The result was:" + ys.dice1); Console.Read (); }}}  

and this is the GUI class form1:

  using the system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; System usage threading. Task; Using System.Windows.Forms; Nameshot Hantzi {Public Partial Class} Form 1: Form {Public Form 1 () {Initial Group (); } Public Zero tbDice_SetText (strings) {//this.ActiveControl = tbDice; Console.WriteLine ("setText"); TbDice.Text = s; } Public Zero Text Box 1 Tag (Object Sender, EventArgse E) {}}}  

The TBDice Text Box is the name of the component. Any ideas?

Check lines:

  Application.Run (ys. Gui); Ys.rollDice ();  

rolls () will not be called until the application gets out, because the thread is running main () Application. Turn on () until it does not.

Instead, try calling ys.rollDice () in something like a button event handler.

> UPDATE

You are mixing your game logic and your presentation logic, by putting both aspects into YahtzeeScorer. I suggest that you take the game logic in a different class like this:

  public class YahtzeeGame {public string rolls (return) rndm.Next (1, 7) .toString ( ); }} Public Partial Category Form 1: Form {YahtzeeGame game = new YahtzeeGame (); Public Form 1 () {Initialization (); } // You need to create a new button on your form called btnRoll and add it as its click handler: Public Zero btnRoll_Clicked (Object Sender, EventArgs e) {tbDice.Text = game.rollDice ( ); }}  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -