CircleLabel.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace ProjectBase.Controls
  11. {
  12. public enum LedState
  13. {
  14. NG = 0,
  15. OK = 1,
  16. DEFAULT = -1,
  17. }
  18. public partial class CircleLabel : UserControl
  19. {
  20. public CircleLabel()
  21. {
  22. InitializeComponent();
  23. }
  24. //protected override void OnResize(EventArgs e)
  25. //{
  26. // base.OnResize(e);
  27. // int x = (int)(0.5 * (this.Width - label1.Width));
  28. // int y = label1.Location.Y;
  29. // label1.Location = new System.Drawing.Point(x, y);
  30. //}
  31. private LedState m_WorkState;
  32. [Browsable(true)]
  33. public LedState WorkState
  34. {
  35. get
  36. {
  37. return m_WorkState;
  38. }
  39. set
  40. {
  41. m_WorkState = value;
  42. SetBackgroundImage();
  43. Refresh();
  44. }
  45. }
  46. private void SetBackgroundImage()
  47. {
  48. switch (WorkState)
  49. {
  50. case LedState.OK:
  51. BackgroundImage = Properties.Resources.绿色指示灯5;
  52. break;
  53. case LedState.NG:
  54. BackgroundImage = Properties.Resources.红色指示灯;
  55. break;
  56. default:
  57. BackgroundImage = Properties.Resources.灰色指示灯;
  58. break;
  59. }
  60. }
  61. private void CircleLabel_FontChanged(object sender, EventArgs e)
  62. {
  63. label1.Font = this.Font;
  64. }
  65. [Browsable(true)]
  66. public override string Text
  67. {
  68. get { return label1.Text; }
  69. set { label1.Text = value; }
  70. }
  71. }
  72. }