I have a “button” comprised of a panel, picturebox and label.
I have disabled the picturebox and label to keep the MouseEnter (and back color) active.
However, the disabled label has the usual faded text – is there a way to keep the label enabled but ignore mouse events as it does when disabled?
Private Sub panelBackup_MouseEnter(sender As Object, e As EventArgs) Handles panelBackupButton.MouseEnter
Dim btn As Panel = DirectCast(sender, Panel)
btn.BackColor = Color.Gray
End Sub
Private Sub panelBackup_MouseLeave(sender As Object, e As EventArgs) Handles panelBackupButton.MouseLeave
Dim btn As Panel = DirectCast(sender, Panel)
btn.BackColor = Color.LightGray
End Sub
Set the same event also for the label
Also I have removed the DirectCast because you could use directly the panelBackup.BackColor property (otherwise you need to add unnecessary additional logic to differentiate the events fired by the panel or by the label.
EDIT: Seeing your comment I have changed the methods reintroducing the cast, but using TryCast to avoid exceptions when the event is raised by a label.
I should mention that probably is possible to TryCast to a generic Control instead of specific Panel or Label because BackColor is a property inherited from the base class (Control)