Your main form:
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:
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);
}
}
}
}
Reputation Points: 1749
Solved Threads: 735
Senior Poster
Offline 3,948 posts
since Feb 2009