MoonToggleButton.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace Optimizer
  9. {
  10. public sealed class MoonToggleButton : Button
  11. {
  12. bool _state;
  13. string _captionYes;
  14. string _captionNo;
  15. public MoonToggleButton()
  16. {
  17. this.DoubleBuffered = true;
  18. CheckForIllegalCrossThreadCalls = false;
  19. _captionYes = Options.TranslationList["btnYes"].ToString();
  20. _captionNo = Options.TranslationList["btnNo"].ToString();
  21. ToggleState = false;
  22. this.Click += MoonToggleButton_Click;
  23. }
  24. private void MoonToggleButton_Click(object sender, EventArgs e)
  25. {
  26. ToggleState = !_state;
  27. }
  28. public bool ToggleState
  29. {
  30. get { return this._state; }
  31. set
  32. {
  33. _state = value;
  34. this.ForeColor = Options.TextColor;
  35. if (_state)
  36. {
  37. this.Text = _captionYes;
  38. this.BackColor = Options.ForegroundColor;
  39. }
  40. else
  41. {
  42. this.Text = _captionNo;
  43. this.BackColor = Options.BackAccentColor;
  44. }
  45. }
  46. }
  47. }
  48. }