473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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
2 1691

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ;...
3
by: Z D | last post by:
Hello, I've created a winform user control that, at some point in the default constructor, looks for a specifc file. When I try to load the user control to my winform's form during design time...
8
by: Ravi Ambros Wallau | last post by:
Hey guys: What can I do when an "Error Creating Control" is displayed on the form (instead of the control), and a tooltip indicating the error never is displayed? Is there some log, some hidden...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
12
by: Dennis | last post by:
I have a form which has a ListView control named ListView1 added at design time. When I add items using the following code, they don't appear in the list view. However, if I create a ListView...
4
by: Raoul Watson | last post by:
I have a form with an AdoDc control associated to a datagrid. The AdoDC uses a "ConnectionString" such as "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..." this is...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
17
by: Kbalz | last post by:
I'm developing a Wizard type program, and I'm flipping between steps by using a TabControl.. buttons on each tabPage move to the next or previous tabPage. When I press CTRL+Tab however, the...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.