0

So I have a presentation game where the answers would be revealed/displayed in Form1 when you click a button from Form2, The answers are displayed with TextBox Winform, But when you click the button from form2 it doesnt change the text of the display textbox, I had already searched in the internet for this problem it solved it but I do not want to make a new window as only the display window will be displayed at on the projector.

Form 1:

public void revealItems(int ItemNo)
{
    Items zItems = JsonSerializer.Deserialize<Items>(File.ReadAllText(loadJson()));
    switch (ItemNo)
    {
        case 1:
            Item1.Text = zItems.ItemArray[0];
            Score1.Text = zItems.ScoreArray[0];
            InitializeComponent();
            break;
    }

Form 2:

public void btnAward1_Click(object sender, EventArgs e)
{
    var frm = new Form1();
    frm.revealItems(1);
}
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • just search "passing value from form 1 to form 2" – T.S. Dec 13 '22 at 02:43
  • You are in `btnAward1_Click` creating a new Form1 and then calling `revealItems(1);` of the new Form1, which isn't showed on screen. (`frm.Show();`). So the instance you already have of Form1 will not even be called and therefor not updated. – Willem Dec 13 '22 at 02:49
  • You should get a reference to the existing Form1 at Form2, and call there `Form1.revealItems(...)`. – Willem Dec 13 '22 at 02:54
  • can you give me an example? – avery-renmin Dec 13 '22 at 05:58

0 Answers0