In C#, how do I make my button's text dynamic? -


i'm newbie when comes coding c#, please don't harsh on me. i've coded actionscript before, , notice it's similar.

anyway, need build simple application 2 characters give each other "money"... or ints. character name should dynamic, , buttons should play off of names are.

please help! have far:

namespace lab_2 {     public partial class form1 : form     {         guy firstname;         guy secondname;         int bank = 100;          public form1()         {             initializecomponent();              firstname = new guy() { cash = 100, name = "joe" };             secondname = new guy() { cash = 50, name = "bob" };              firstname = textbox1.text;             secondname = textbox2.text;              updateform();         }          public void updateform()         {             name1cashlabel.text = firstname.name + " has $" + firstname.cash;             name2cashlabel.text = secondname.name + " has $" + secondname.cash;             bankcashlabel.text = "the bank has $" + bank;         }          private void button1_click(object sender, eventargs e)         {             button1.text = "give $10 " + firstname.name;              if (bank >= 10)             {                 bank -= firstname.receivecash(10);                 updateform();             }             else             {                 messagebox.show("the bank out of money.");             }         }          private void button2_click(object sender, eventargs e)         {             bank += secondname.givecash(5);             updateform();         }          private void button3_click(object sender, eventargs e)         {             secondname.receivecash(firstname.givecash(10));             updateform();         }          private void button4_click(object sender, eventargs e)         {             firstname.receivecash(secondname.givecash(5));             updateform();         }          private void name1_click(object sender, eventargs e)         {             firstname.name = textbox1.text;         }     } } 

if wanna show new names on buttons, can update them simple so:

private void name1_click(object sender, eventargs e)  {      firstname.name = textbox1.text;      button1.text = "give $10 " + firstname.name; } 

and maybe same name2_click (if have):

private void name2_click(object sender, eventargs e)  {      secondname.name = textbox2.text;      button2.text = "give $10 " + secondname.name; } 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -