Hi, I was wondering if you guys can help me sort this out. I've
basically got a custom button which inherits from the Button class, and
this button is used throughout my forms. The custom button has a state
'permission' and what basically happens is that if this button is
clicked on any form, it checks if the button has an associated
'permission', and the event action in the child form must only be fired
if the person clicking the button has that 'permission'. My code
currently looks something like this (simplified, of course):
public class MyButton : Button
{
private string permission;
public MyButton() : base
{
this.Click += new EventHandler(MyButton_Click);
}
public string Permission
{
set
{
this.permission = value;
}
}
private bool PersonHasPermission(permission)
{
//checks if the person has the permission
}
private void MyButton_Click(object sender, EventArgs e)
{
if (permission != null && permission != "")
{
if (!PersonHasPermission(permission))
{
//what do i put here to stop the event in MyForm from firing further?
}
}
}
}
public class MyForm
{
public MyForm()
{
MyButton myButton = new MyButton();
myButton.Click += new EventHandler(myButton_Click);
myButton.Permission = "Can_click_this_button";
}
private void myButton_Click(object sender, EventArgs e)
{
//this is the stuff that I want to happen only if the person has the
required permission, else do nothing, but i do not want to do an
explicit check here, since it is already being done in the MyButton
class
}
}
If you look at line 29 in my code, I need something to put there to
stop the event from firing in the child button, which is on line 47,
but I do not want to put an explicit check there, as that is already
done in the parent class. Another reason is that making the check
explicit would entail a LOT of changes having to be made because the
button is already used on a lot of forms, so I really want to minimize
the code changes. Someone please help me :(