473,394 Members | 2,020 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,394 software developers and data experts.

How to know the design time and run time?

How can I know whether it is design state or run state of C#.
Nov 16 '05 #1
3 6228
"Steven.Xu" <St******@discussions.microsoft.com> wrote in message news:26**********************************@microsof t.com...
How can I know whether it is design state or run state of C#.


You have to ask this question of something "designable", like an IComponent or
a Control (WinForms or ASP.NET Control). These types will all expose a
property named Site (of type System.ComponentModel.ISite). Note that Form
(in WinForms) and Page (in ASP.NET) also inherit from their respective Control
base classes, so they can be sited.

On ISite, there is a boolean property named 'DesignMode' that you can check.
It will be True when your component or control is in the design-mode.

For example, in ASP.NET within Page_Load you could write,

if ( ( Page.Site != null ) && ( Page.Site.DesignMode ) )
// Do design-time only operations here.
else
// Do run-time only operations here.

Before checking the DesignMode property, always test that the control is sited
(i.e., it's Site property is non-null). When null, that indicates the control is also
at run-time (no Site means no possibility of it being design-time).
Derek Harmon
Nov 16 '05 #2
Are you talking about Windows Forms? In this situation you can check the DesignMode property of the form or control. Be aware, however, that this value is not set in the constructor. If you want to do initialization checking of DesignMode then implement ISupportInitialize

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

How can I know whether it is design state or run state of C#.

Nov 16 '05 #3
Ben
I don't now where you need it for, but if something else should happen while
debugging than in the final release of your application, use compiler hints,
like this:

#if DEBUG
// Some code only to execute while debugging!
#endif

For this to work, activate your Debug configuration for the solution.

Gr,
Cybenny

Hello Steven.Xu,
How can I know whether it is design state or run state of C#.

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rushikesh | last post by:
I am designing a WEB BASED Accounting Software with ASP and SQL Server. For this I need some help for the Database design. My design is as follows. I)User table: User_id, UserName..... Users...
1
by: Mark | last post by:
I have .aspx code-behinds that inherit from the class below. The code runs just fine, but the form designer bombs at design time when trying to view the .aspx page in VS.NET 2003. If I comment...
1
by: malcolm | last post by:
Hello, We use several user controls and derived custom controls. Some of which actually hit the database at design time to show data (such as filling a list box, etc...) Our c# client server...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
5
by: A_M_IS | last post by:
Dear valuable experts, I truly hope than You can suggest for me Your ideas how to resolve design. I developing relative small Access VB tool, for single user use only. Access version 2003, but db...
6
by: Skysurfer | last post by:
Is it possible to know when a control is added to a form in Design time? I tryed with ControlAdded, but this is also fired when the program starts. I want to set some properties only when a...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.