-1

Hello I'm kind of new to C# and I'm trying to get one form to talk to another form in the same namespace. So the button the first button is on form1 and it opens up form2 then I want the user to click a button in form2 to make a button in form1 visible that was previously invisible. This is what I have for button 1 on form1.

Form2 MainWindow = new Form2();
MainWindow.Show();

The is what I have for the button on form2.

Form1.button2.Visible = true;
Konamiman
  • 49,681
  • 17
  • 108
  • 138
Evilshig
  • 5
  • 2
  • You might pass the data in the constructor of the form. you have to make a constructor overload that receive the data object like **new Form2( new CustomObject(){ value1="something "});** and then process the data sent – Carlos487 May 03 '18 at 14:22
  • Possible duplicate of [Interaction between forms — How to change a control of a form from another form?](https://stackoverflow.com/questions/38768737/interaction-between-forms-how-to-change-a-control-of-a-form-from-another-form) – Ondrej Tucny May 29 '18 at 09:23

1 Answers1

0

You can do something like this:

public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

        }

   private void button1_Click(object sender, EventArgs e)
        {
Form2 form2 = new Form2(this);
form2.ShowDialog();
        }

///to set the visibility of things you want 
        public void SetVisibility(bool visibility)
        {
button1.Visibility = visibility;
        }

    }

///Form2

public partial class Form2 : Form
    {
private Form1 parentForm;
        public Form1()
        {
            InitializeComponent();

        }

   public Form1(Form parentForm)
        {
            InitializeComponent();
this.parentForm = parentForm;
        }
///to set the visibility of things you want 
   private void button1_Click(object sender, EventArgs e)
        {
parentForm.SetVisibility(true);
        }


    }

But my advise is to learn basics first as this is simple stuff and is not worthy posting here .

Dharani Kumar
  • 457
  • 2
  • 8