You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.0 KiB

3 years ago
  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 UserControlLib
  11. {
  12. public partial class UserButton : UserControl
  13. {
  14. public UserButton()
  15. {
  16. InitializeComponent();
  17. }
  18. public string BtnText
  19. {
  20. get
  21. {
  22. return button.Text;
  23. }
  24. set
  25. {
  26. button.Text = value;
  27. }
  28. }
  29. /// <summary>
  30. /// 按钮Tag值变化事件调用方法 由外部触发
  31. /// </summary>
  32. public void ButtonTagValueChanged(string tagTypeId, string value)
  33. {
  34. if (tagTypeId == TagTypeId)
  35. {
  36. Value = value=="true"?true:false;
  37. if (Value)
  38. {
  39. button.BackColor = Color.LightBlue;
  40. }
  41. else
  42. {
  43. button.BackColor = Color.LightGray;
  44. }
  45. }
  46. }
  47. public string GroupId { get; set; }
  48. bool tagValue;
  49. public bool Value
  50. {
  51. get
  52. {
  53. return tagValue;
  54. }
  55. set
  56. {
  57. tagValue = value;
  58. if (tagValue)
  59. {
  60. button.BackColor = Color.LightBlue;
  61. }
  62. else
  63. {
  64. button.BackColor = Color.LightGray;
  65. }
  66. }
  67. }
  68. public string TagTypeId { get; set; }
  69. /// <summary>
  70. /// 按钮单击事件
  71. /// </summary>
  72. public Action<string, bool> TagButtonClickEvent;
  73. private void button_Click(object sender, EventArgs e)
  74. {
  75. TagButtonClickEvent?.Invoke(this.TagTypeId, !Value);
  76. }
  77. }
  78. }