ControlEnabler.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Windows.Forms;
  3. namespace LYFZ.NeroDiscBurn.NET
  4. {
  5. /// <summary>
  6. /// Summary description for ControlEnabler.
  7. /// </summary>
  8. public class ControlEnabler
  9. {
  10. private Form m_form;
  11. private bool [] m_bControlStates = null;
  12. public ControlEnabler(Form form)
  13. {
  14. m_form = form;
  15. }
  16. public void EnableAllControls (bool bEnable)
  17. {
  18. if (bEnable)
  19. {
  20. if (m_bControlStates != null)
  21. {
  22. // Restore state of each form control.
  23. //
  24. int i = 0;
  25. foreach (Control ctrl in m_form.Controls)
  26. {
  27. ctrl.Enabled = m_bControlStates[i];
  28. }
  29. }
  30. }
  31. else
  32. {
  33. // Allocate an array big enough to store enable states
  34. // for all controls on a form.
  35. //
  36. m_bControlStates = new bool[m_form.Controls.Count];
  37. // Store states for all controls in an array and
  38. // disable each of them.
  39. //
  40. int i = 0;
  41. foreach (Control ctrl in m_form.Controls)
  42. {
  43. m_bControlStates[i] = ctrl.Enabled;
  44. ctrl.Enabled = false;
  45. }
  46. }
  47. }
  48. }
  49. }