467,920 Members | 1,240 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,920 developers. It's quick & easy.

How can Control/Form know if it's being displayed during design or in runtime?

I have created a control that displays a list of items. During design
mode I fill it with junk data using calls from the constructor. So
when I look at a form with the control on, instead of being empty, it
has some content, and this gives a better idea of what the form will
look like when run. During runtime it should be empty to start with,
so I comment out the code in the constructor that fills it with dummy
data.

How can I code the control/form so that the constructor knows it is
being shown in design mode?

Thanks in advance for any replies.

(My appologies for use of the term "know" in relation to a software
program.)

Oct 13 '06 #1
  • viewed: 1517
Share:
2 Replies

TerryStone wrote:
How can I code the control/form so that the constructor knows it is
being shown in design mode?
maybe this will help:

http://msdn2.microsoft.com/en-us/library/35ea88wb.aspx

or this:

http://msdn.microsoft.com/msdnmag/is...2/CuttingEdge/

To quote Dino: "The IComponent interface has just one property, Site,
which corresponds to an object that implements the ISite interface. The
ISite interface defines four properties: Component, Container,
DesignMode, and Name".

if (this.Site != null && this.Site.DesignMode)
{
string buf = "'{0}' is hosted by {1}";
MessageBox.Show(String.Format(buf, this.Site.Name,
this.Site.Container.ToString()));
}
else
MessageBox.Show("The control works in a run-time context.");

Eric

Oct 13 '06 #2

TerryStone wrote:
I have created a control that displays a list of items. During design
mode I fill it with junk data using calls from the constructor. So
when I look at a form with the control on, instead of being empty, it
has some content, and this gives a better idea of what the form will
look like when run. During runtime it should be empty to start with,
so I comment out the code in the constructor that fills it with dummy
data.

How can I code the control/form so that the constructor knows it is
being shown in design mode?
You can't.

There is a DesignMode property that tells you whether you are in design
mode, but it is correct only after your control / form has a window
handle, which happens well after it is constructed.

You need to move your dummy-data populating code from your constructor
into an OnLoad routine / Load event handler. In there, the DesignMode
property will return the correct result, and you can suppress
populating your form when not in design mode.

Oct 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Z D | last post: by
12 posts views Thread by Dennis | last post: by
4 posts views Thread by Raoul Watson | last post: by
17 posts views Thread by Kbalz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.