muhammad islam muhammad islam - 1 year ago 57
Vb.net Question

How to stop a user from pressing a button more than once

I've got a small problem of having a button and a combo box. In this situation the combobox holds values from 1 to 10. The enter button allows the user to select how many dynamic objects they want to produce however my program crashes every time I press enter after selecting another value and pressing enter again. So is there any form of validation I can have for my button to stop users from pressing enter twice.

Answer Source

Use a flag to supress user events.

Clear it again if need be at the appropriate time.

Private Enter_Locked As Boolean
Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
    If Enter_Locked Then Exit Sub
    Enter_Locked = True
    'do as you will here

End Sub
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download