private void ClearTextbox() { foreach (Control ctrlpanel in groupBox2.Controls) { if (ctrlpanel.GetType().Name.ToString() == "Panel") { foreach (Control tbPanel in ctrlpanel.Controls) { if (tbPanel.GetType().Name.ToString() == "Panel") { if (tbPanel.Name.Contains("_")) { foreach (Control TbCtrl in tbPanel.Controls) { if (TbCtrl.GetType().Name.ToString().ToLower() == "textbox") { TextBox tb = (TextBox)TbCtrl; tb.Text = string.Empty; } } } } } } } tbPerAdd_Street.Text = tbPerAdd_Brgy.Text = tbPerAdd_City.Text = tbPerAdd_Postal.Text = string.Empty; tbPreAdd_Street.Text = tbPreAdd_Brgy.Text = tbPreAdd_City.Text = tbPreAdd_Postal.Text = string.Empty; }
public void ControlObjects(bool status, GroupBox gp) { try { foreach (Control ctrlpanel in gp.Controls) { if (ctrlpanel.GetType().Name.ToString() == "Panel") { foreach (Control tbPanel in ctrlpanel.Controls) { if (tbPanel.GetType().Name.ToString() == "Panel") { if (tbPanel.Name.Contains("_")) { foreach (Control TbCtrl in tbPanel.Controls) { if (TbCtrl.GetType().Name.ToString().ToLower() == "textbox") { TextBox tb = (TextBox)TbCtrl; tb.Enabled = status; tb.Enter += new EventHandler(tb_Enter); tb.Leave += new EventHandler(tb_Leave); tb.KeyPress += new KeyPressEventHandler(tb_KeyPress); tb.KeyDown += new KeyEventHandler(tb_KeyDown); } if (TbCtrl.GetType().Name.ToString().ToLower() == "combobox") { ComboBox cb = (ComboBox)TbCtrl; cb.Enabled = status; cb.Enter += new EventHandler(cb_Enter); cb.Leave += new EventHandler(cb_Leave); cb.KeyPress += new KeyPressEventHandler(cb_KeyPress); cb.KeyDown += new KeyEventHandler(cb_KeyDown); } if (TbCtrl.GetType().Name.ToString().ToLower() == "datetimepicker") { DateTimePicker dtpick = (DateTimePicker)TbCtrl; dtpick.Enabled = status; dtpick.Enter += new EventHandler(dtpick_Enter); } if (TbCtrl.GetType().Name.ToString().ToLower() == "groupbox") { GroupBox gb = (GroupBox)TbCtrl; foreach (Control ctrlGB in gb.Controls) { if (ctrlGB.GetType().Name.ToString().ToLower() == "textbox") { TextBox tbGB = (TextBox)ctrlGB; tbGB.Enabled = status; tbGB.Enter += new EventHandler(tb_Enter); tbGB.Leave += new EventHandler(tb_Leave); tbGB.KeyPress += new KeyPressEventHandler(tb_KeyPress); tbGB.KeyDown += new KeyEventHandler(tb_KeyDown); } } } } } } } } } } catch { } }