disable using "protected override void OnPaint(..." method.

R

ramo9941

Hi,

Is there any way disable using "protected override void OnPaint(..." method
out of the assembly. I create usercontrol and i do not want user adds extra
codes OnPaint method for securtity purpose. And i don't give a permission to
call "CreateGraphics()".

Thanks your responses.
 
P

Peter Morris

protected override sealed void OnPaint..........
{
}

Add the word "sealed" after "override"
 
R

ramo9941

i had used your advice but it has alreay used onpaint outside of the
assembly. I can add "private void graph2D1_Paint(object sender,
PaintEventArgs e)" method from properties->events->paint but ı don't this
event calling.
 
J

Jon Skeet [C# MVP]

ramo9941 said:
i had used your advice but it has alreay used onpaint outside of the
assembly. I can add "private void graph2D1_Paint(object sender,
PaintEventArgs e)" method from properties->events->paint but ? don't this
event calling.

That's adding an event handler for the Paint event, which isn't the
same as overriding the OnPaint method. And no, you can't prevent that.
 
R

ramo9941

ok,
if user adds under codes to "graph2D1_Paint" method:
base.OnPaint(e);
MessageBox.Show("1");
Has any protection mechanism this state?

And same as above state protect to not caling "CreateGraphics()" method
outside of the assembly.

thanks yor replies.
 
J

Jon Skeet [C# MVP]

ramo9941 said:
if user adds under codes to "graph2D1_Paint" method:
base.OnPaint(e);
MessageBox.Show("1");
Has any protection mechanism this state?

No. You can't stop them from calling methods they're normally allowed
to call. That violates object oriented principles. If you don't want
users to be calling certain methods, you shouldn't be deriving from a
class which exposes those methods.
 
B

Ben Voigt [C++ MVP]

Jon said:
No. You can't stop them from calling methods they're normally allowed
to call. That violates object oriented principles. If you don't want
users to be calling certain methods, you shouldn't be deriving from a
class which exposes those methods.

As in:

Instead of inheriting, make the object you want to limit access to a private
member (or even a private nested class derived from the base class). Then
you can call any methods on it you want, and intercept any calls your user
makes, because they are not called on the protected object but rather on
your class.
 

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