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

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
Button has Enabled property. If it is set to false, it is not drawn and user
can not click on it.
 
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.
 
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;
 
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 ;
}
}
.....
}
 
Back
Top