Discussion:
Runtime or designtime
(too old to reply)
Johnny E. Jensen
2009-12-12 02:48:12 UTC
Permalink
Hello NG

I am using Visual Studio 2008 C#

Is it possible to determine when i am in edit mode or runtime mode.
I have a usercontrol that makes it impossible to view the form its placed on
in design mode, but works fine in runtime.

I do know the problem why it wont display the form, and can solve the
problem by place the "reason code" in a try-catch, but i would prefer to
determine whether i am in design- or runtime mode.

Kind regards
Johnny Jensen.
Jeff Gaines
2009-12-12 09:13:59 UTC
Permalink
Post by Johnny E. Jensen
Hello NG
I am using Visual Studio 2008 C#
Is it possible to determine when i am in edit mode or runtime mode.
I have a usercontrol that makes it impossible to view the form its placed
on in design mode, but works fine in runtime.
I do know the problem why it wont display the form, and can solve the
problem by place the "reason code" in a try-catch, but i would prefer to
determine whether i am in design- or runtime mode.
Kind regards
Johnny Jensen.
In your constructor use something like:

public JExplorerPanel()
{
InitializeComponent();
if (!this.DesignMode)
JExplorerPanelInitialise();
}
--
Jeff Gaines Dorset UK
There is absolutely no substitute for a genuine lack of preparation
Jack Jackson
2009-12-13 05:14:39 UTC
Permalink
On Sat, 12 Dec 2009 01:13:59 -0800, "Jeff Gaines"
Post by Jeff Gaines
Post by Johnny E. Jensen
Hello NG
I am using Visual Studio 2008 C#
Is it possible to determine when i am in edit mode or runtime mode.
I have a usercontrol that makes it impossible to view the form its placed
on in design mode, but works fine in runtime.
I do know the problem why it wont display the form, and can solve the
problem by place the "reason code" in a try-catch, but i would prefer to
determine whether i am in design- or runtime mode.
Kind regards
Johnny Jensen.
public JExplorerPanel()
{
InitializeComponent();
if (!this.DesignMode)
JExplorerPanelInitialise();
}
That will often work, but be aware that This.DesignMode is only true
if the control is being designed in the IDE. If you have this code in
a control that has been dropped in a UserControl, and you drop the
UserControl on a form, when you design the form this.DesignMode will
not be true for the inside control since that control is not being
designed.

Another way to go is to use this code:

Dim processName As String =
System.Diagnostics.Process.GetCurrentProcess().ProcessName
If processName = "devenv" OrElse
processName.EndsWith("TestContainer") Then
m_isDesignMode = True
End If

According to info I found on the Web, this code can sometimes take a
long time to execute, and under some circumstances can throw an
exception. Therefore I only execute it once in my application object,
and put it inside a Try / Catch.
Jeff Gaines
2009-12-13 09:18:48 UTC
Permalink
Post by Jack Jackson
On Sat, 12 Dec 2009 01:13:59 -0800, "Jeff Gaines"
Post by Jeff Gaines
public JExplorerPanel()
{
InitializeComponent();
if (!this.DesignMode)
JExplorerPanelInitialise();
}
That will often work, but be aware that This.DesignMode is only true
if the control is being designed in the IDE. If you have this code in
a control that has been dropped in a UserControl, and you drop the
UserControl on a form, when you design the form this.DesignMode will
not be true for the inside control since that control is not being
designed.
Now that is very interesting and explains a behaviour I have seen but
couldn't understand, many thanks - it's had me puzzled for a long time :-)
Post by Jack Jackson
Dim processName As String =
System.Diagnostics.Process.GetCurrentProcess().ProcessName
If processName = "devenv" OrElse
processName.EndsWith("TestContainer") Then
m_isDesignMode = True
End If
According to info I found on the Web, this code can sometimes take a
long time to execute, and under some circumstances can throw an
exception. Therefore I only execute it once in my application object,
and put it inside a Try / Catch.
I will give that a try, having noted the caveat.

If I am in a situation with a control inside another control would
'walking up the tree' to the parent control work? Without actually trying
it something like:

if ((!this.DesignMode) || (!this.Parent.DesignMode)) etc.
--
Jeff Gaines Dorset UK
There is absolutely no substitute for a genuine lack of preparation
Jack Jackson
2009-12-13 20:42:57 UTC
Permalink
On Sun, 13 Dec 2009 01:18:48 -0800, "Jeff Gaines"
Post by Jeff Gaines
Post by Jack Jackson
On Sat, 12 Dec 2009 01:13:59 -0800, "Jeff Gaines"
Post by Jeff Gaines
public JExplorerPanel()
{
InitializeComponent();
if (!this.DesignMode)
JExplorerPanelInitialise();
}
That will often work, but be aware that This.DesignMode is only true
if the control is being designed in the IDE. If you have this code in
a control that has been dropped in a UserControl, and you drop the
UserControl on a form, when you design the form this.DesignMode will
not be true for the inside control since that control is not being
designed.
Now that is very interesting and explains a behaviour I have seen but
couldn't understand, many thanks - it's had me puzzled for a long time :-)
Post by Jack Jackson
Dim processName As String =
System.Diagnostics.Process.GetCurrentProcess().ProcessName
If processName = "devenv" OrElse
processName.EndsWith("TestContainer") Then
m_isDesignMode = True
End If
According to info I found on the Web, this code can sometimes take a
long time to execute, and under some circumstances can throw an
exception. Therefore I only execute it once in my application object,
and put it inside a Try / Catch.
I will give that a try, having noted the caveat.
If I am in a situation with a control inside another control would
'walking up the tree' to the parent control work? Without actually trying
if ((!this.DesignMode) || (!this.Parent.DesignMode)) etc.
I have a vague recollection that I tried this, and this.DesignMode
only worked from within the class. If so, you still do this if you
use only subclassed controls and added a method to each to return
this.DesignMode.
Slavic Schupak
2010-01-06 18:13:28 UTC
Permalink
Post by Jack Jackson
On Sat, 12 Dec 2009 01:13:59 -0800, "Jeff Gaines"
Post by Jeff Gaines
Post by Johnny E. Jensen
Hello NG
I am using Visual Studio 2008 C#
Is it possible to determine when i am in edit mode or runtime mode.
I have a usercontrol that makes it impossible to view the form its placed
on in design mode, but works fine in runtime.
I do know the problem why it wont display the form, and can solve the
problem by place the "reason code" in a try-catch, but i would prefer to
determine whether i am in design- or runtime mode.
Kind regards
Johnny Jensen.
public JExplorerPanel()
{
InitializeComponent();
if (!this.DesignMode)
JExplorerPanelInitialise();
}
That will often work, but be aware that This.DesignMode is only true
if the control is being designed in the IDE. If you have this code in
a control that has been dropped in a UserControl, and you drop the
UserControl on a form, when you design the form this.DesignMode will
not be true for the inside control since that control is not being
designed.
Dim processName As String =
System.Diagnostics.Process.GetCurrentProcess().ProcessName
If processName = "devenv" OrElse
processName.EndsWith("TestContainer") Then
m_isDesignMode = True
End If
According to info I found on the Web, this code can sometimes take a
long time to execute, and under some circumstances can throw an
exception. Therefore I only execute it once in my application object,
and put it inside a Try / Catch.
Both implementation work, but DesignMode property will always return false
in Constructor, even if it's used in some control, which is initialized in
some form's constructor.
So be carefully using it ;-)

P.s. exception handling in designtime worth special post

Loading...