-2

I want to disable a label as soon as it is clicked however the code hides the label.

What I want is to disable it (make darkgrey and unclickable), not make it disappear.

  Label3.Enabled = False
nalply
  • 26,770
  • 15
  • 78
  • 101
LabRat
  • 1,996
  • 11
  • 56
  • 91
  • 1
    Is this a label or Textbox control? Since a label doesn't provide any default interaction. Or did you add an onclick handler to your label? – JMan Feb 18 '13 at 09:40
  • 1
    i added a click event and expected it to work like a button qua enable disable also (not so) – LabRat Feb 18 '13 at 09:42
  • when the `Label3.Enabled = False`? the result is actually hide? – spajce Feb 18 '13 at 09:46
  • Maybe your form `BackgroundColor` is the same as the `Label` color when is not enabled? And `Label3.Enabled = False` should disable the click event. – SysDragon Feb 18 '13 at 09:46
  • 1
    lol yes my background was black stuipid me :) – LabRat Feb 18 '13 at 09:59

1 Answers1

0

Add your onclick event like this:

AddHandler Label3.Click, AddressOf MyClickMethod

Keep track of the state of your click and implement your method like this:

Private _isActive As Boolean

Public Sub MyClickMethod(ByVal o As Object, ByVal e As EventArgs)
   If _isActive Then
       RemoveHandler Label3.Click, AddressOf MyClickMethod
       _isActive = False
   Else
       AddHandler Label3.Click, AddressOf MyClickMethod
       _isActive = True
   EndIf
End Sub

Could be I'm missing some syntax, typing outside of visual studio

nalply
  • 26,770
  • 15
  • 78
  • 101
JMan
  • 2,611
  • 3
  • 30
  • 51