Click here to Skip to main content
15,942,672 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi , I am trying to lock a button in my form , i have tried with the following
btnSubmit_CrtIss.Enabled = False
btnReset_CrtIss.Enabled = False

but it looks awful, just like a greyed out text box, my goal is to prevent users from clicking those buttons.
Please help

You could just eat the event if the button is locked. However, making the button disabled is the standard indisutry way of saying "you can't use this control right now".

If you don't like the grayed-out appearance, you could always completely hide them, but I can tell you from a number of years of experience designing user interfaces that users don't really like it when stuff just disappears from the screen.
Share this answer
I've had customers complain that when textboxes are disabled or even just readonly they can't read the value in them. To get around things like that I have a variable that tracks when things are supposed to be read-only. Then every event for those controls just gets skipped when that variable is set to true. So, something like this:

Dim boolMakeReadOnly as Boolean = True

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If boolMakeReadOnly Then Return 'This exits the event

'Original code for the submit button (gets skipped if boolMakeReadOnly is true)

End Sub
Share this answer
Yusuf 29-Jul-10 14:03pm    
You can make the text box read only (I'm not sure about VB, but the C based languages do this). If the control is readonly, it is not disabled but the user can't change the value. Personally, I don't like it, as you can distinguish between what is disabled and enabled controls.
Kschuler 29-Jul-10 14:05pm    
right, but when you set the read only it sill makes the textbox grey. I was saying that my customers didn't like that and this was my work around.
I don't know if this is possible, give it a shot

<br />
btnSubmit_CrtIss.Readonly= False<br />
btnReset_CrtIss.Readonly= False
Share this answer
souvikd 29-Jul-10 14:51pm    
i have already tried that, readonly doesnt work for buttons

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900