User_Element.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace OTSRptPeriodicTable
  5. {
  6. public partial class User_Element : UserControl
  7. {
  8. #region 变量
  9. public int i_click = 0; //点击记数
  10. Color old_color; //记录被点击前的颜色
  11. string str_zwysm = "中文元素名";
  12. //中文元素名
  13. public string zwysm
  14. {
  15. get { return str_zwysm; }
  16. set { str_zwysm = value; }
  17. }
  18. /// <summary>
  19. /// 该控件的原始颜色
  20. /// </summary>
  21. public Color OldColor
  22. {
  23. get { return old_color; }
  24. set { old_color = value; }
  25. }
  26. #endregion
  27. #region 窗体加载,初始化
  28. public User_Element()
  29. {
  30. InitializeComponent();
  31. }
  32. //加载
  33. private void User_Element_Load(object sender, EventArgs e)
  34. {
  35. lb_zwysm.Text = "";
  36. old_color = this.BackColor;
  37. #region 字太多,变小点显示
  38. string str = this.lb_ywm.Text;
  39. if (str.Length > 8)
  40. {
  41. lb_ywm.Font = new Font("微软雅黑", 6, FontStyle.Bold);
  42. }
  43. #endregion
  44. }
  45. #endregion
  46. #region 鼠标移动事件
  47. private void User_Element_MouseMove(object sender, MouseEventArgs e)
  48. {
  49. Graphics g = this.CreateGraphics();
  50. ControlPaint.DrawBorder(g,
  51. this.ClientRectangle,
  52. Color.Lime,
  53. 1,
  54. ButtonBorderStyle.Solid,
  55. Color.Lime,
  56. 1,
  57. ButtonBorderStyle.Solid,
  58. Color.Lime,
  59. 1,
  60. ButtonBorderStyle.Solid,
  61. Color.Lime,
  62. 1,
  63. ButtonBorderStyle.Solid);
  64. }
  65. private void User_Element_MouseLeave(object sender, EventArgs e)
  66. {
  67. Graphics g = this.CreateGraphics();
  68. ControlPaint.DrawBorder(g,
  69. this.ClientRectangle,
  70. old_color,
  71. 1,
  72. ButtonBorderStyle.Solid,
  73. old_color,
  74. 1,
  75. ButtonBorderStyle.Solid,
  76. old_color,
  77. 1,
  78. ButtonBorderStyle.Solid,
  79. old_color,
  80. 1,
  81. ButtonBorderStyle.Solid);
  82. }
  83. #endregion
  84. #region 鼠标点击事件
  85. private void User_Element_MouseClick(object sender, MouseEventArgs e)
  86. {
  87. if (i_click == 0)
  88. {
  89. lb_zwysm.Text = str_zwysm;//点击到其它颜色时显示中文名,深灰色
  90. i_click = 2;
  91. this.BackColor = Color.SpringGreen;
  92. return;
  93. }
  94. if (i_click == 2)
  95. {
  96. //换回原先的颜色
  97. lb_zwysm.Text = ""; //恢复到原先的颜色时,不显示中文名
  98. i_click = 0;
  99. this.BackColor = old_color;
  100. return;
  101. }
  102. }
  103. #endregion
  104. }
  105. }