0

how do I make one of my form's Checkbox set to enabled from a different form?

I have tried several things, which seem none worked.

           if (i == 0)
            {
                MessageBox.Show("Login Failed.");
            }
            else
            {
                MessageBox.Show("Login Successful.");
                Hide();
                Hacks mainForm = this.Parent as Hacks;
                if (mainForm != null)
                {
                    checkBox1.Visible = true;
                    mainForm.Show();
                }

This is the code I Currently have, after a successful login from the server, a message box is displayed saying: Login Successful. What I want it to do is after successful login, to enable the checkbox on the mainform. Since mainform is there, and I do have a checkbox, why can't it enable the checkbox; as it appears to not do so. What am I doing wrong?

Ryan Ellis
  • 13
  • 4
  • 2
    Does this answer your question? [Communicate between two windows forms in C#](https://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp) – JohnG Nov 28 '21 at 22:21

1 Answers1

-1

You should change modifier of the element to public. After that you can change the properties of the element by

mainForm.checkBox1.Visible = true;
Ahmetcan Aksu
  • 53
  • 2
  • 10