views:

44

answers:

3

I've looked into the DesignOnly attribute, but that doesn't seem to accomplish what I want*.

Basically, I'm looking for some way to indicate that some property of a user control (let's say Text) can be modified during design time -- i.e., from the Windows Forms designer in VS (or presumably from any GUI designer that can be used to modify a Windows Forms GUI) -- but not during run time. Once the application is running, the property should effectively be readonly.

Is this possible?

* When I add the DesignOnly attribute to a property, the value I select for that property from design mode doesn't seem to stick; the property just ends up being whatever I have it set to by default in code.

A: 

It might be important to note that Design-Time support is runtime support. Your objects are being spun up in the background by the IDE. Designer support is just a bunch of IDE meta-data that allows Visual Studio (or some other designer) to build a graphical representation of your objects.

There is no "real" difference between runtime and design time. If you want to see what I am talking about try throwing a NotImplementedException in one of your properties and attempt to set it in the designer.

Josh
A: 

You cannot do this - the VS forms designer generates code that runs just like any other code at runtime; so you cannot distinguish between VS forms code and user code. Have a look at the InitializeComponent method - this is run just like any other code when the form is created.

thecoop
+1  A: 

You can put a public static varible in your app wbhich you can set to true in the main()-method. You can then test if the variable is set. If so, then the program has been started normally, otherwise we obviously run in designer.

codymanix
I suppose this really makes the most sense.
Dan Tao
@Dan: using the DesignMode property of a control makes sense too.
Hans Passant