简体   繁体   中英

Input from main form to another form

I want to receive an input to the 2nd form from the main form.
I've tried to generate a method in the 2nd form, that's what I got:

internal Form2 Method(string value)
{
    throw new NotImplementedException();
}  

The value from the 1st form should be passed into "value" variable.
How do I return "value" as a string, so I can use it?

By the way, I don't know how to work with "internal" access modifier.

You can create one class like

Public Class ValueTransfer
 {
  public string Value1{get;set;}
  }

Now you can create a Object of ValueTenasfer from from1 like

ValueTransfer v=new ValueTransfer();
 v.Value1="string";

and pass the class object into Other from method

You don't need to create method just add one parameter constructor for second form so that whenever you need to pass value in second form at that time just create a object of second form with parameter whatever you want to pass to it else just create object with without parameter.

Form1()
{
     String to_pass = "abcdefg";
     Form2 formsecond = New Form2(to_pass);         
}

Form2(string to_pass)
{
     MessageBox.Show(to_pass);
}

But Dont Forget to Add parameterised Constructor before use this otherwise you get error for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM