Clicking disabled button still raises event

G

Guest

Hi,

I have a button, which I disable after it has been clicked. it gets enabled
when all processing (code that gets executed when the button is clicked) is
done.

Looks like this:
Private Sub btnLabel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLabel.Click
'** Code
End sub

However, when the disabled button is clicked, afterwards those clicks are
done.

I tried removing the handler for the click event like so:
RemoveHandler bnLabel.Click, AddressOf btnLabel.Click

This doesn't seem to work either.

With BlockInput I can block evry input, but this isn't quite the behavior
I'm looking for. The user can't do anthing anymore, and that's no good.

Anyone having an idea.
Thanks already.
Bjorn.
 
R

recoil

Perhaps a simple check in your btnLabel_Click

if not sender is nothing and sender.enabled=false return

This should checks to make sure that sender is not null (useful if
somewhere in yoour code you ever call the event with null parameters)
and then it checks if the object which should be the label itself is
enabled. If itis not it returns.
 
G

Guest

Ok thanks for the reply.

I'll try to make my situation a bit cleare with following simplified example:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Not sender Is Nothing And sender.enabled = False Then Return
MyOperation()
End Sub

Private Sub MyOperation()
InitControls(False)

'Dim frm2 As Form2
'frm2 = New Form2
'frm2.f = Me
'frm2.Show()
System.Threading.Thread.CurrentThread.Sleep(3000)
i = i + 1
Me.Text = i
'RaiseEvent ProcessingDone()

InitControls(True)
End Sub

Private Sub InitControls(ByVal OperationDone As Boolean)
Select Case OperationDone
Case True
' if your operation is complete then:
Button2.Enabled = True
Case False
' if your operation is starting or is currently running then:
Button2.Enabled = False
End Select
End Sub



This doesn't work, multiple clicks get processed.
I tried creating an event (code in comment in MyOperation method), and
catching it in another popup form, which than closes that second form. This
doesn't work either.

What I could do is position the popup window above the button (so it can't
be clicked no more), but I don't like this kind of solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top