Reputation: 1241
Here I'm facing problem,I'm adding form dynamically into tab page. I have to get a static variable from that form.
i used code,but i can't get exact value which i need.
private void timer2_Tick(object sender, EventArgs e)
{
foreach (TabPage page in tabControl1.TabPages)
{
Control control = page.Controls[0];
if(!hyber.Form1.receiverflag)//bug line
{
tabControl1.TabPages.Remove(page);
}
}
}
In the above pic watch window
page.controls[0] ->[hyber.form1] -->receiverflag
how to get that variable value.
Thanks in advance.
Upvotes: 1
Views: 1347
Reputation: 44605
you are nor clear about bug line or in saying can't get the exact value you need.
if the variable is a public static bool
it belongs to the class and not to the instance, being static, so when you write:
hyber.Form1.receiverflag
you are taking the variable's value regardless of the specific instance of Form1 you are dealing with, does not matter at all if you have created one instance and added to the TabPage, that variable always exists even if you do not create any instance.
if you are getting wrong/unexpected results could be, eventually, that another thread or another method has changed the value of that static field and this reflects everywhere in your application.
Edit: if it was not static, you could probably get what you are asking in this way:
var yourForm1 = (page.Controls[0] as hyber.Form1);
if( yourForm1 != null && !yourForm1.receiverflag)
{
....
Upvotes: 1