| | |
Checking controlproperties of child from parent
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2005
Posts: 13
Reputation:
Solved Threads: 0
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:
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!
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:
C# Syntax (Toggle Plain Text)
Form2 form2 = new Form2(this); form2.Show();
But this obviolusly just opens a new "fresh" form every time.
Need some help in the right direction.
Any help is appreciated!
Your main form:
Your other form:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace daniweb.checkboxes { public partial class frmMain : Form { private frmOther frm; public frmMain() { InitializeComponent(); } private void frmMain_Load(object sender, EventArgs e) { frm = new frmOther(); } private void buttonShowOtherForm_Click(object sender, EventArgs e) { frm.Show(); } private void buttonHideOtherForm_Click(object sender, EventArgs e) { frm.Hide(); } private void buttonCheckAll_Click(object sender, EventArgs e) { frm.SetCheckValue(true); } private void buttonUncheckAll_Click(object sender, EventArgs e) { frm.SetCheckValue(false); } } }
Your other form:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace daniweb.checkboxes { public partial class frmOther : Form { public frmOther() { InitializeComponent(); } private void frmOther_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; this.Hide(); } public void SetCheckValue(bool Checked) { foreach (Control c in this.Controls) { SetCheckValue(Checked, c); } } private static void SetCheckValue(bool Checked, Control c) { CheckBox cb = (c as CheckBox); if (cb != null) cb.Checked = Checked; foreach (Control childCtrl in c.Controls) { SetCheckValue(Checked, childCtrl); } } } }
•
•
Join Date: Jul 2009
Posts: 956
Reputation:
Solved Threads: 198
•
•
•
•
Wow, thank you very much. Works like a charm!
You almost made it too easy for me
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.
![]() |
Similar Threads
- Class with child and parent (C#)
- Database design for child care (Database Design)
- XPath: selecting ALL children, based on value of single child (XML, XSLT and XPATH)
- Regular expression class with child/parent (C#)
- java (JavaScript / DHTML / AJAX)
- How to pass information to child processes (PHP)
- Parent/Child Windows References (JavaScript / DHTML / AJAX)
- Control Child Window After parent refresh W/O Frames (HTML and CSS)
Other Threads in the C# Forum
- Previous Thread: Changing specific picture box background
- Next Thread: Reading Listbox values of other window
| Thread Tools | Search this Thread |
Tag cloud for check, checkbox, form, forms
6 action ajax applicaions asp.net basic beginner box button buttons c# cgi check checkbox code coldfusion combo content cookies copy creat data database datagridview datagridviewcheckbox development dgv directrobot dom download drawing dynamically element email enter exists feedback files form forms gdi+ gui header html http if...loop image insert java javascript linkedlist listbox login math multiple mysql net news open oracle password paypal perl php post radio remote robot security select table thread tree treeview trouble upload validation validator vb vb6 video visual visualbasic visualbasic6 web webbrowser website window windows wpf xss zend







