Button.xaml.vb 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. Public Class Button
  2. '声明
  3. Public Event Click(ByVal sender As Object, ByVal e As EventArgs) '自定义事件
  4. '自定义属性
  5. Public Property Text As String
  6. Get
  7. Return labText.Content
  8. End Get
  9. Set(ByVal value As String)
  10. labText.Content = value
  11. End Set
  12. End Property '显示文本
  13. Public Property TextPadding As Thickness
  14. Get
  15. Return labText.Padding
  16. End Get
  17. Set(ByVal value As Thickness)
  18. labText.Padding = value
  19. End Set
  20. End Property
  21. Private _ColorType As State = State.COMMON '配色方案
  22. Public Property ColorType As State
  23. Get
  24. Return _ColorType
  25. End Get
  26. Set(ByVal value As State)
  27. _ColorType = value
  28. RefreshColor()
  29. End Set
  30. End Property
  31. Public Enum State As Byte
  32. COMMON = 0
  33. HIGHLIGHT = 1
  34. RED = 2
  35. End Enum
  36. '自定义事件
  37. Private Sub RefreshColor() Handles Me.MouseEnter, Me.MouseLeave, Me.Loaded, Me.IsEnabledChanged
  38. Try
  39. If Me.IsEnabled Then
  40. Select Case Me._ColorType '选取颜色种类
  41. Case State.COMMON
  42. If Me.IsMouseOver Then
  43. '指向
  44. AniStart({ _
  45. AaBackGround(Border, New MyColor(Color.FromArgb(255, 248, 248, 248)) - Border.Background, 150),
  46. AaBorderBrush(Me, New MyColor(Color.FromArgb(255, 42, 42, 42)) - Me.BorderBrush, 150),
  47. AaOpacity(Me, 1 - Me.Opacity, 200)
  48. }, "BtnColor" & Me.Name)
  49. Else
  50. '普通
  51. AniStart({ _
  52. AaBackGround(Border, New MyColor(Color.FromArgb(128, 248, 248, 248)) - Border.Background, 150),
  53. AaBorderBrush(Me, New MyColor(Color.FromArgb(255, 42, 42, 42)) - Me.BorderBrush, 150),
  54. AaOpacity(Me, 0.8 - Me.Opacity, 200)
  55. }, "BtnColor" & Me.Name)
  56. End If
  57. Case State.HIGHLIGHT
  58. If Me.IsMouseOver Then
  59. '高亮指向
  60. AniStart({
  61. AaBackGround(Border, New MyColor(Color.FromArgb(255, 248, 248, 248)) - Border.Background, 150),
  62. AaBorderBrush(Me, New MyColor(CType(Application.Current.Resources("Color5"), SolidColorBrush).Color) - Me.BorderBrush, 150),
  63. AaOpacity(Me, 1 - Me.Opacity, 200)
  64. }, "BtnColor" & Me.Name)
  65. Else
  66. '高亮普通
  67. AniStart({
  68. AaBackGround(Border, New MyColor(Color.FromArgb(128, 248, 248, 248)) - Border.Background, 150),
  69. AaBorderBrush(Me, New MyColor(CType(Application.Current.Resources("Color5"), SolidColorBrush).Color) - Me.BorderBrush, 150),
  70. AaOpacity(Me, 0.8 - Me.Opacity, 200)
  71. }, "BtnColor" & Me.Name)
  72. End If
  73. Case State.RED
  74. If Me.IsMouseOver Then
  75. '红色指向
  76. AniStart({ _
  77. AaBackGround(Border, New MyColor(Color.FromArgb(255, 248, 248, 248)) - Border.Background, 150),
  78. AaBorderBrush(Me, New MyColor(Color.FromArgb(255, 200, 20, 20)) - Me.BorderBrush, 150),
  79. AaOpacity(Me, 1 - Me.Opacity, 200)
  80. }, "BtnColor" & Me.Name)
  81. Else
  82. '红色普通
  83. AniStart({ _
  84. AaBackGround(Border, New MyColor(Color.FromArgb(128, 248, 248, 248)) - Border.Background, 150),
  85. AaBorderBrush(Me, New MyColor(Color.FromArgb(255, 200, 20, 20)) - Me.BorderBrush, 150),
  86. AaOpacity(Me, 0.8 - Me.Opacity, 200)
  87. }, "BtnColor" & Me.Name)
  88. End If
  89. End Select
  90. Else
  91. '灰色(不可用)
  92. AniStart({ _
  93. AaBackGround(Border, New MyColor(Color.FromArgb(128, 248, 248, 248)) - Border.Background, 150),
  94. AaBorderBrush(Me, New MyColor(Color.FromArgb(255, 144, 144, 144)) - Me.BorderBrush, 150),
  95. AaOpacity(Me, 0.8 - Me.Opacity, 200)
  96. }, "BtnColor" & Me.Name)
  97. End If
  98. Catch ex As Exception
  99. ExShow(ex, "刷新按钮出错")
  100. End Try
  101. End Sub
  102. '默认事件
  103. Private Sub Button_Mouse(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonUp
  104. RaiseEvent Click(sender, e)
  105. End Sub
  106. End Class