-1

so I have looked this up so much and nothing fits exactly what I want.

I have one form open called "Main" it has a button in it that opens up a form using the code

AddModification modification = new AddModification();
Modification.Show();

Now this opens the form correctly and all. But the problem is that both forms are open. So the AddModification form is a popup form that changes things in the Main Form.

So the AddModification form is opened / shown but the form itself is broken because I can't put Main main = new Main(); in the AddModification form without a stack overflow problem.

So how the heck do I access any of Main's controls in AddModification if I need to keep main and AddModification open and not disposed?

  • It would be better to show all relevant code in regards to the main form an how you are setting and or trying to access values of the second form.. show the other forms code as well – MethodMan Feb 21 '16 at 00:51
  • There is no need for this because I have already shown everything that is needed. This is exactly how I show the forms, and I already told you exactly how I'm trying to access the values of the other from. I simply used Main main = new Main(); and then i'd do main.Controlofsomesort.visible = true; – Swiftly Team Feb 21 '16 at 01:03
  • There is a similar question with good answers here: – SusanGHP Feb 21 '16 at 19:11

2 Answers2

3

You need to pass the first form as a constructor parameter to the second form.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Exactly how would I do that. I'm pretty new to C# I am use to using Objective C and Swift – Swiftly Team Feb 21 '16 at 00:53
  • Can I get an example actually – Swiftly Team Feb 21 '16 at 00:57
  • public class YourForm1 : UserControl { public void OpenOtherForm() { var opened_form = new YourForm2(this); } } public class YourForm2 : UserControl { public YourForm2(YourForm1 Owner) { // do something with YourForm1 here } } – Bogey Feb 21 '16 at 01:07
0

Have you tried something like 'this.Owner' ?

Ashraf Iqbal
  • 412
  • 3
  • 11