How to pass values between forms in c# windows application?

后端 未结 4 1453
渐次进展
渐次进展 2020-11-27 08:18

I have two forms A and B. Form A is the default start up form of the application. I do some stuffs in Form A and i then i want to run my Form B parallel and then pass a para

4条回答
  •  一整个雨季
    2020-11-27 08:51

    FormA should construct/hold an instance to FormB. Obviously the method on FormB needs to be public, change the type of object used in CallMethodOnFormB to the correct type too.

    public class FormA
    {
       private FormB fB;
    
       public void CreateFormB()
       { 
          // This shows the form in parallel.
          this.fB = new FormB();
          this.fB.Show();
       }
    
       public void CallMethodOnFormB(object value)
       {
          this.fB.RunSomeFunction(value);
       }
    }
    

提交回复
热议问题