I have a form main
and it include a textbox companyname
and other form name is Form1
and a class ListViewPrinter.cs
under Form1.cs
.I just want to get companyname
value from ListViewPrinter.cs
. I tried to do
TextBox com = Application.OpenForms["main"].Controls["companyname"] as TextBox;
but it gives me NullReferenceException was unhandled by user code
.How can I get companyname
You need to either make the class ListViewPrinter
static or create an instance of it. Google for these two terms to get an idea.
You may declare main form as static and get the value as you will get it from main.
public static main main_ = new main();
....
string txtValue = main_.companyname;
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.