How can I access custom button property during button contructor?

G

Guest

I have a custom button control that compares the user security level to the
buttons security level property. If the user level is greater than the
button level, then the button is enabled, else it is disabled. Now for the
three questions:
1) I tried to retrieve the buttons security level property during the
buttons constructor, but it can't get the actual value assigned to that
button until sometime after the contructor finishes. Is there any way to get
that value during the buttons constructor?
2) Then I moved the logic to disable the button to the property SET method.
The problem with this, is that if the security is set high enough to disable
the button, then it shows up in the designer as disabled, and I can not get
back to the buttons properites to change the security value again. Is there
some way to flag the code to not perform some lines of code if it is in
designer mode?
3) I also tried to put it in the OnPaint property, but then it just went
into an infinite loop. It must automatically call the OnPaint property if
the button is disabled?
 
M

Mattias Sjögren

Is there
some way to flag the code to not perform some lines of code if it is in
designer mode?

Sure, you can check if you're in design mode using something like

if ( Site != null && Site.DesignMode ) ...



Mattias
 
G

Guest

In C# using windows forms, I was able to use this.DesignMode and it worked
great!

Thanks for the help.
 
R

Richard Blewett [DevelopMentor]

Note that this.DesignMode isn't set in the control's constructor (as it only knows when its site is set as it reads it from the site). The standard way to get roud this is to implement ISupportInitialize - then VS.NET emits a call to ISupportInitialize .BeginInit and ISupportInitialize.EndInit in the InitializeComponent

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

In C# using windows forms, I was able to use this.DesignMode and it worked
great!

Thanks for the help.
 

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