我有一个检查日志文件的按钮,如果文本与特定字符串不匹配,则按钮被禁用。我是这样做的:
button.enabled = False
这会按预期禁用控件 - 但我想保持启用MouseHover事件。
是否可以禁用点击?
修改
在悬停时更改文字:
Private Sub AIR_Button_MouseHover(sender As Object, e As EventArgs) Handles AIR_Button.MouseHover
Dim AIRfileReader As String
AIRfileReader = My.Computer.FileSystem.ReadAllText("X:\Logs\Air\AirConnectedUser.txt")
AIR_Button.Text = AIR_Button.Text.Replace("Air", AIRfileReader)
End Sub
Private Sub AIR_Button_MouseLeave(sender As Object, e As EventArgs) Handles AIR_Button.MouseLeave
Dim AIRfileReader As String
AIRfileReader = My.Computer.FileSystem.ReadAllText("X:\Logs\Air\AirConnectedUser.txt")
AIR_Button.Text = AIR_Button.Text.Replace(AIRfileReader, "Air")
End Sub
禁用按钮:
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText("X:\Logs\ConnectionState.txt")
If fileReader.Contains("AIR Account logged in") Then
AIR_Button.BackColor = Color.IndianRed
AIR_Button.Enabled = False
End Sub