By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

How can I access custom button property during button contructor?

P: n/a
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?
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2

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

Thanks for the help.

"Mattias Sjögren" wrote:
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 17 '05 #3

P: n/a
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.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.