L
Laser Lu
Hi, I'm a novice in .NET Windows Forms programming. Recently, I was stumbled
by a puzzle, regarding how to determine whether the code is currently
executing under design-time or not.
My code was written in C# under Visual Studio .NET 2003. In my project, I
just created a Windows Form as a base form, and then inherited another
Windows Form based on that one. Everything works fine. But, after I had
added some custom code into the base form's OnLoad event handler, the
problem occurs that the inherited form can no longer be openned in the
designer. And the designer says that "An error occurred while loading the
document".
Here is the skeleton code snippets:
public class MyBaseForm : System.Windows.Forms.Form
{
protected override void OnLoad(EventArgs e)
{
try
{
// some custom code was added here,
// which may be error prone at design time
...
}
catch
{
}
base.OnLoad (e);
}
}
public class InheritedForm : MyBaseForm
{
// this inherited form can not be loaded by the designer,
// if some error was thrown within the base form's code
...
}
So, the question is obvious. How to make a design mode detection and avoid
uncessary errors during design-time in my custom code?
Thanks,
Laser Lu
by a puzzle, regarding how to determine whether the code is currently
executing under design-time or not.
My code was written in C# under Visual Studio .NET 2003. In my project, I
just created a Windows Form as a base form, and then inherited another
Windows Form based on that one. Everything works fine. But, after I had
added some custom code into the base form's OnLoad event handler, the
problem occurs that the inherited form can no longer be openned in the
designer. And the designer says that "An error occurred while loading the
document".
Here is the skeleton code snippets:
public class MyBaseForm : System.Windows.Forms.Form
{
protected override void OnLoad(EventArgs e)
{
try
{
// some custom code was added here,
// which may be error prone at design time
...
}
catch
{
}
base.OnLoad (e);
}
}
public class InheritedForm : MyBaseForm
{
// this inherited form can not be loaded by the designer,
// if some error was thrown within the base form's code
...
}
So, the question is obvious. How to make a design mode detection and avoid
uncessary errors during design-time in my custom code?
Thanks,
Laser Lu