congdantoancau

Reset controls in Windows form

Apr 25th, 2018
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. foreach (var item in this.Controls)
  2.             {
  3.                 // Reset Textbox
  4.                 if (item.GetType().Equals(typeof(TextBox)))
  5.                 {
  6.                     TextBox t = item as TextBox;
  7.                     t.Text = string.Empty;
  8.                 }
  9.  
  10.                 // Reset Combobox
  11.                 if (item.GetType().Equals(typeof(ComboBox)))
  12.                 {
  13.                     ComboBox c = item as ComboBox;
  14.                     c.SelectedIndex = -1;
  15.                     c.ResetText();
  16.                 }
  17.  
  18.                 // Reset RadioButton
  19.                 if (item.GetType().Equals(typeof(RadioButton)))
  20.                 {
  21.                     RadioButton r = item as RadioButton;
  22.                     r.Checked = false;
  23.                 }
  24.  
  25.                 // Reset CheckedListBox
  26.                 if (item.GetType().Equals(typeof(CheckedListBox)))
  27.                 {
  28.                     CheckedListBox cl = item as CheckedListBox;
  29.  
  30.                     foreach (int i in cl.CheckedIndices)
  31.                     {
  32.                         cl.SetItemCheckState(i, CheckState.Unchecked);
  33.                     }
  34.                 }            
  35.             }
Advertisement
Add Comment
Please, Sign In to add comment