Hello, well basically, i created a windows form application when i started my project and i have created two extra forms (options and about). The options tab has a few checkbox's like: minimize to tray and top-most program and in my main form i have the code:
but i can't find a way to read the properties of the controls on form3(Options), i tried changing the controls in the designer code portion of the form from private to public, but still no success. I would really appreciate any help on this topic. Thanks in advance.
7 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 18, 2009, 10:19 AM EDT
✓ Accepted answer0
Code
Error is Because you have not Opened Options Form
Below code will work if Option Form is Open
so in form1's Load Event Write
form1_load(Object Sender,EventArgs e)
{
Options f2 = new Options();
f2.Show
}
//then after this will work :)
private void form1_Resize(object sender, EventArgs e)
{
Form f = Application.OpenForms["Options"];
bool CheckBox1State = ((Options)f).checkBox1.Checked;
if (this.WindowState == FormWindowState.Minimized == true && CheckBox1State == true)
{
notifyIcon1.Visible = true;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
}
If still need assistance let me know i will help you :)
and friend , please check "Do you like this answer" if my answer helped you :)
0
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 18, 2009, 8:55 AM EDT
0
Friend,
Here is code for what you are trying to do Here Requirement is Your Options Form Should Be Open to Access the CheckBox in It :)
dont forget to mark "Do you like this answer" if my answer helped you :)
Step 1
Make CheckBox1's Property "Modifire = "Public" in Options Form like below image
Then Write Code Like Below Where ever you want to access CheckBox
Serban Cosmin59 reputationPosted Oct 18, 2009, 9:22 AM EDT
0
Marking the control ( CheckBox ) as public in the form you've created is enough to access it. So, if you have the Options class with the public property checkBox1, and have :
Options myOptions = new Options( ); , you should be able to call myOptions.checkBox1 without any other formalities. Make sure your classes share the same namespace or ar properly accessed across namespaces and that in your code the field is declared with a public modifier, regardless of what you set in the designer. Also, maybe building the project before accessing this field would help.
0
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 18, 2009, 9:33 AM EDT
0
C#
privatevoidform1_Resize(object sender, EventArgs e)
{
Form f = Application.OpenForms["Options"];
bool CheckBox1State = ((Options)f).checkBox1.Checked;
if (this.WindowState == FormWindowState.Minimized == true && CheckBox1State == true)
{
notifyIcon1.Visible = true;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
}
Here in Highlighted code Use Your Option Form's Name Properties Value I used Options Because i Named Form Option :)
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 18, 2009, 10:19 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 18, 2009, 8:55 AM EDT
Here is code for what you are trying to do Here Requirement is Your Options Form Should Be Open to Access the
CheckBox in It :)
dont forget to mark "Do you like this answer" if my answer helped you :)
Step 1
Make CheckBox1's Property "Modifire = "Public" in Options Form like below image
Then Write Code Like Below Where ever you want to access CheckBox
//Get CheckBox1State in Options
Form f = Application.OpenForms["Options"];
bool CheckBox1State = ((Options)f).checkBox1.Checked;
if (this.WindowState == FormWindowState.Minimized == true && CheckBox1State == true)
{
notifyIcon1.Visible = true;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
Enc Rypt10 reputationPosted Oct 18, 2009, 9:21 AM EDT
private void form1_Resize(object sender, EventArgs e) { Form f = Application.OpenForms["Options"]; bool CheckBox1State = ((Options)f).checkBox1.Checked; if (this.WindowState == FormWindowState.Minimized == true && CheckBox1State == true) { notifyIcon1.Visible = true; this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; } }Serban Cosmin59 reputationPosted Oct 18, 2009, 9:22 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 18, 2009, 9:33 AM EDT
private void form1_Resize(object sender, EventArgs e) { Form f = Application.OpenForms["Options"]; bool CheckBox1State = ((Options)f).checkBox1.Checked; if (this.WindowState == FormWindowState.Minimized == true && CheckBox1State == true) { notifyIcon1.Visible = true; this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; } } Here in Highlighted code Use Your Option Form's Name Properties Value I used Options Because i Named Form Option :)Enc Rypt10 reputationPosted Oct 18, 2009, 10:12 AM EDT
on the Form "f", i tried putting Form f = new form(); before the code and it didn't help. it shows the contents of f as "null"
Enc Rypt10 reputationPosted Oct 18, 2009, 10:26 AM EDT