Which button event would work the best to disable the button.

G

Guest

I would like to disable a button on the form if the user is not authorized to
use it.

I've created a custom button and would like for each button to know if it
should be enabled or disabled based on another class that would contain the
users authority levels.

I know I can use the on form load event, but I rather test to see if the
user has access to the button during the buttons OnPaint event? If they
don't have access, I'd like to disable the button. So should I use the
OnPaint event for the button, or is there an event that would be more
appropriate.
 
L

Lebesgue

Button has Enabled property. If it is set to false, it is not drawn and user
can not click on it.
 
G

Guest

I know that, but when would be a good time to set the buttons enable property
to false if the user doesn't have authority. So should I set it to false
during the button paint event, or some other event.
 
L

Lebesgue

I know that, but when would be a good time to set the buttons enable property
to false if the user doesn't have authority. So should I set it to false
during the button paint event, or some other event.

You should set it to false once, whenever you want. I don't find Paint event
very suitable, try to set it when the conditions deteminig if it should be
available change. It will stay false until you set it to true;
 
G

Guest

How about if I do it during the buttons constructor as follows:

public class ButtonExit : Button
{
public ButtonExit() : base()
{
// If user doesn't have enough authority, then disable this button.
if (!Authorized(ButtonSecurityLevel))
{
this.Enabled = false ;
}
}
.....
}
 

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