Checking controlproperties of child from parent

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2005
Posts: 13
Reputation: MillStrike is an unknown quantity at this point 
Solved Threads: 0
MillStrike MillStrike is offline Offline
Newbie Poster

Checking controlproperties of child from parent

 
-1
  #1
Oct 1st, 2009
Hi!
I'm going crazy about this problem.
Here's the setup:
On my mainform I have a menustrip from where I can open a new form (form2) with different controls like checkboxes etc. After I've modified these controls I close or hide that form and continue using the mainform.
Now here's my problem, how do I check from the mainform if ex. a checkbox is checked in form2? Also when I reopen form2 the controls should remain as I modified them last before closing form2 (It would look like to the user that he saves thouse settings).

I've tried:
  1. Form2 form2 = new Form2(this);
  2. form2.Show();
And then use a button to hide it.
But this obviolusly just opens a new "fresh" form every time.

Need some help in the right direction.
Any help is appreciated!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,328
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 600
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Checking controlproperties of child from parent

 
0
  #2
Oct 1st, 2009
Your main form:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace daniweb.checkboxes
  11. {
  12. public partial class frmMain : Form
  13. {
  14. private frmOther frm;
  15.  
  16. public frmMain()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void frmMain_Load(object sender, EventArgs e)
  22. {
  23. frm = new frmOther();
  24. }
  25.  
  26. private void buttonShowOtherForm_Click(object sender, EventArgs e)
  27. {
  28. frm.Show();
  29. }
  30.  
  31. private void buttonHideOtherForm_Click(object sender, EventArgs e)
  32. {
  33. frm.Hide();
  34. }
  35.  
  36. private void buttonCheckAll_Click(object sender, EventArgs e)
  37. {
  38. frm.SetCheckValue(true);
  39. }
  40.  
  41. private void buttonUncheckAll_Click(object sender, EventArgs e)
  42. {
  43. frm.SetCheckValue(false);
  44. }
  45. }
  46. }

Your other form:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace daniweb.checkboxes
  11. {
  12. public partial class frmOther : Form
  13. {
  14. public frmOther()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. private void frmOther_FormClosing(object sender, FormClosingEventArgs e)
  20. {
  21. e.Cancel = true;
  22. this.Hide();
  23. }
  24.  
  25. public void SetCheckValue(bool Checked)
  26. {
  27. foreach (Control c in this.Controls)
  28. {
  29. SetCheckValue(Checked, c);
  30. }
  31. }
  32.  
  33. private static void SetCheckValue(bool Checked, Control c)
  34. {
  35. CheckBox cb = (c as CheckBox);
  36. if (cb != null)
  37. cb.Checked = Checked;
  38. foreach (Control childCtrl in c.Controls)
  39. {
  40. SetCheckValue(Checked, childCtrl);
  41. }
  42. }
  43.  
  44. }
  45. }
Attached Files
File Type: zip daniweb.checkboxes.zip (16.1 KB, 4 views)
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 13
Reputation: MillStrike is an unknown quantity at this point 
Solved Threads: 0
MillStrike MillStrike is offline Offline
Newbie Poster

Re: Checking controlproperties of child from parent

 
0
  #3
Oct 2nd, 2009
Wow, thank you very much. Works like a charm!
You almost made it too easy for me
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 956
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 198
DdoubleD DdoubleD is offline Offline
Posting Shark

Re: Checking controlproperties of child from parent

 
0
  #4
Oct 3rd, 2009
Originally Posted by MillStrike View Post
Wow, thank you very much. Works like a charm!
You almost made it too easy for me
I thought you were asking how you could determine from main form whether the checkboxes on form2 are checked or unchecked, but it looks like you have your answer.

Please mark this thread as solved. EDIT: Looks like you already did... I'm losing my mind me thinks...
Last edited by DdoubleD; Oct 3rd, 2009 at 10:10 am.
Reply With Quote Quick reply to this message  
Reply

Tags
check, checkbox, form, forms

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for check, checkbox, form, forms
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC