/DualityEditor/Controls/ToolStrip/ToolStripCheckBox.cs

http://duality.googlecode.com/ · C# · 57 lines · 51 code · 5 blank · 1 comment · 1 complexity · ba486184824109fc0b7e2ef1344dfaa5 MD5 · raw file

  1. using System;
  2. using System.Windows.Forms;
  3. using System.Windows.Forms.Design;
  4. namespace DualityEditor.Controls.ToolStrip
  5. {
  6. [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
  7. public class ToolStripCheckBox : ToolStripControlHost
  8. {
  9. private CheckBox checkBox = null;
  10. public event EventHandler CheckedChanged
  11. {
  12. add { this.checkBox.CheckedChanged += value; }
  13. remove { this.checkBox.CheckedChanged -= value; }
  14. }
  15. public event EventHandler CheckStateChanged
  16. {
  17. add { this.checkBox.CheckStateChanged += value; }
  18. remove { this.checkBox.CheckStateChanged -= value; }
  19. }
  20. public override string Text
  21. {
  22. get { return this.checkBox.Text; }
  23. set
  24. {
  25. this.checkBox.Text = value;
  26. this.UpdateAutoSize();
  27. }
  28. }
  29. public bool Checked
  30. {
  31. get { return this.checkBox.Checked; }
  32. set { this.checkBox.Checked = value; }
  33. }
  34. public CheckState CheckState
  35. {
  36. get { return this.checkBox.CheckState; }
  37. set { this.checkBox.CheckState = value; }
  38. }
  39. public ToolStripCheckBox() : base(new CheckBox())
  40. {
  41. // Set up the FlowLayouPanel.
  42. this.checkBox = (CheckBox)base.Control;
  43. this.checkBox.AutoSize = true;
  44. }
  45. protected void UpdateAutoSize()
  46. {
  47. if (!this.AutoSize) return;
  48. this.AutoSize = false;
  49. this.AutoSize = true;
  50. }
  51. }
  52. }