Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Designer and Runtime only code (Preprocessor directives)
 

Designer and Runtime only code (Preprocessor directives)

Hello,

I thought I came across this earlier but unfortunaly I can't seem to find this again.

It was this code using Proprocessor directives that would allow the user to assign code that would only get executed during Design time.

I have this Form that changes it's size depending on the content. The method gets called in the Load event. This code should, however, only get executed during Runtime and NOT during Design time.

How would I do this?

Kind regards,

~ Sph

saphua_fk  Tuesday, October 30, 2007 3:27 PM

Hi

Sample:

private void Form1_Load(object sender, EventArgs e)

{

if (!this.DesignMode)

{

MessageBox.Show("Not in design time");

}

}

Regards

Flo

Florian Reischl  Tuesday, October 30, 2007 5:09 PM

Hi

Sample:

private void Form1_Load(object sender, EventArgs e)

{

if (!this.DesignMode)

{

MessageBox.Show("Not in design time");

}

}

Regards

Flo

Florian Reischl  Tuesday, October 30, 2007 5:09 PM
There's the property for a control called "DesignMode" which is set to true by the designer and is false when running the program normally.

you can prevent code from running during the design time with:
if ( !DesignMode )
{
// code to run only during runtime
}

this only applies to things that can be rendered in Design Mode (forms, custom controls, etc)
IsshouFuuraibou  Tuesday, October 30, 2007 5:11 PM

You can use google to search for other answers

Custom Search

More Threads

• Button Click not firing after Validation event
• Is it possible to change the ActionScript values if I only have the .swf file?
• ".resx" files not kept up-to-date by Visual Studio
• Ann: SharpLibrary Released
• Another Code generation for Property XXX failed.
• Need some help with an Enum TypeConverter, I think
• Where do I ask about C# User Controls
• where can I download RegionMaster Controls?
• Datagrid View column ordering bug.
• generate additional file/class/struct from component