Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing variable 1

Status
Not open for further replies.

kokon

Programmer
Apr 27, 2006
31
0
0
PL
Please help me, I cannot access variable or checkbox state from another class. My code is:

Form1 kol = new Form1();
if (kol.checkBox1.Checked) StartVpnCon();
MessageBox.Show(kol.checkBox1.Checked.ToString());
-----------
But MessageBox always show "false" no matter of the real checkbox state.
 
you have to expose that property through your form:

public class Form1 : System.Windows.Forms.Form
{
private CheckBox checkBox1 = new CheckBox();

public Form1()
{
InitializeComponents();
}

public bool StartVPNIsChecked
{
get
{
return checkBox1.Checked;
}
}
}


if (kol.StartVPNIsChecked == true)
{
MessageBox.Show("VPN Checkbox Is Checked");
}
 
Sorry but its not working, maybe because the :
---------
if (kol.StartVPNIsChecked == true)
{
MessageBox.Show("VPN Checkbox Is Checked");
}
---------
is called from another thread also.
 
ah!

Threading is wonderful :)


Your new thread should not need to pull data from a gui item on the main thread. You might want to re-consider your architecture.

You should be able to set a value on the thread when the checkbox status changes though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top