473,513 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to prevent code from being executed by the Designer?

How can I prevent a few lines of code contained in the constructor of a Form
from being executed by the Designer?

Thanks,
Fabio
Dec 28 '05 #1
7 8799
Fabio,

Check the DesignMode property of the control that you have. If it
returns true, then you are in design mode.

This is inherited from Component.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fabio Cannizzo" <fc*****************@london.edu> wrote in message
news:43**********************@reader3.news.tin.it. ..
How can I prevent a few lines of code contained in the constructor of a
Form from being executed by the Designer?

Thanks,
Fabio

Dec 28 '05 #2
Fabio,

When developing user controls or custom controls, I SOMETIMES use
this.DesignMode to prevent things from being created.

Why do you need it for a form?

Dave

"Fabio Cannizzo" <fc*****************@london.edu> wrote in message
news:43**********************@reader3.news.tin.it. ..
How can I prevent a few lines of code contained in the constructor of a
Form from being executed by the Designer?

Thanks,
Fabio

Dec 28 '05 #3
"Fabio Cannizzo" <fc*****************@london.edu> wrote in
news:43**********************@reader3.news.tin.it:
How can I prevent a few lines of code contained in the constructor of
a Form from being executed by the Designer?


Check the DesignMode property of the form.

if (!this.DesignMode)
{
// Code here only executes when running, not in design mode
}

-mdb
Dec 28 '05 #4
Thanks to all of you guys.

In reality I need this in an object inherited from UserControl, not from
Form.

The constructor of my UserControl will create some unmanaged objects using
interops, and I suspect this is what is causing lots of problems with my VS.
See my other post just two hours ago: "Bad UserControl in toolbox".

Regards,
Fabio
"D. Yates" <fo****@hotmail.com> wrote in message
news:eH****************@TK2MSFTNGP09.phx.gbl...
Fabio,

When developing user controls or custom controls, I SOMETIMES use
this.DesignMode to prevent things from being created.

Why do you need it for a form?

Dave

"Fabio Cannizzo" <fc*****************@london.edu> wrote in message
news:43**********************@reader3.news.tin.it. ..
How can I prevent a few lines of code contained in the constructor of a
Form from being executed by the Designer?

Thanks,
Fabio


Dec 28 '05 #5
Since you are doing this work in a UserControl, you might find that you need
to move some of the code out of the constructor to get the DesignMode
property to function correctly:

http://groups.google.com/groups?as_q...e+gone+in+.Net
http://groups.google.com/groups?as_q=Design+Mode+-+My+Constructor+keeps+running+in+design!
"Fabio Cannizzo" <fc*****************@london.edu> wrote in message
news:43**********************@reader3.news.tin.it. ..
Thanks to all of you guys.

In reality I need this in an object inherited from UserControl, not from
Form.

The constructor of my UserControl will create some unmanaged objects using
interops, and I suspect this is what is causing lots of problems with my VS. See my other post just two hours ago: "Bad UserControl in toolbox".

Regards,
Fabio
"D. Yates" <fo****@hotmail.com> wrote in message
news:eH****************@TK2MSFTNGP09.phx.gbl...
Fabio,

When developing user controls or custom controls, I SOMETIMES use
this.DesignMode to prevent things from being created.

Why do you need it for a form?

Dave

"Fabio Cannizzo" <fc*****************@london.edu> wrote in message
news:43**********************@reader3.news.tin.it. ..
How can I prevent a few lines of code contained in the constructor of a
Form from being executed by the Designer?

Thanks,
Fabio



Dec 29 '05 #6
I also found this:
Debugging Design-Time Controls
http://msdn.microsoft.com/library/de...edebugging.asp

which u might find interesting.

Dave
Dec 29 '05 #7
Learn something new everyday.....

This article mentions what u said:
http://msdn.microsoft.com/library/de...edebugging.asp

Any class that derives from the Component class has a property called
DesignMode that is set to true when the code is executing within the
constructs of the Visual Studio .NET designer. So you have the option to
wrap code within an if statement. There's one more trick, however. The
DesignMode property isn't set to true in the constructor. Remember, there's
no real magic here. Visual Studio .NET creates your object as it parses the
InitializeComponent() method. Once the object is constructed, Visual Studio
..NET keeps track of the objects it creates.....

Microsoft needs to update the documentation for Component.DesignMode
Property:

http://msdn.microsoft.com/library/de...nmodetopic.asp

to reflect this information!!!
Dave
Dec 29 '05 #8

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

Similar topics

9
6193
by: Felix Wiemann | last post by:
Sometimes (but not always) the __new__ method of one of my classes returns an *existing* instance of the class. However, when it does that, the __init__ method of the existing instance is called...
20
2851
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
1
1580
by: bid | last post by:
I have 2 controls on this page as shown below. The first is a datalist control which contains links to the particular image gallery (second control) I want to display. However I only want the...
2
11367
by: crjunk | last post by:
I have the following code in my web page. Dim tmpReplace As String 'Giving tmpReplace the value from the textbox on the webform. tmpReplace = txtComments.Text.Trim 'Prevents report from...
1
1454
by: Russ | last post by:
I've been trying to get my head around this for 3 days now and it seems like everything I try does not work for one reason or another. I built a test page using the TabStrip and MultiPage controls....
3
3217
by: Ryu | last post by:
Hi, May I know how to prevent Javascript from being dlownloaded when the user saves at "View Source"? I have added "js" at IIS's application configuration's mapping and i have added the...
7
2624
by: Sharon | last post by:
I'm writing my own control that derived from the UserControl. In my control I have some public properties (with get and set) that I do not want them to be shown on the designer properties window...
3
1958
by: sowencheung | last post by:
I attach an Event in document.onkeyup and another event in document.onbeforeunload in onkeyup event, if the condition is satisfied, i will activate sth, then i don't want the onbeforeunload...
3
1402
by: Qu0ll | last post by:
In browsers which utilise a JIT JavaScript compiler, are there any factors that may prevent a script from being compiled before it is executed? I don't see any reason why this would be so but I...
0
7259
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
7158
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
7380
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,...
1
7098
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
7523
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
5683
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,...
1
5085
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...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.