473,322 Members | 1,504 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,322 software developers and data experts.

Design time problems

Is there any boolean flag set during design time that a UserControl can test
to see whether to run code that only works during runtime (because of
complicated initialization)?

Like this:

public class MyControl : UserControl {
public MyControl() {
InitializeComponent();
if (!System.ComponentModel.Design.MagicClass.IsDesign Time)
DoSomethingUnsafeAtDesignTime();
}
}

Otherwise, I can't put my control on my form with the designer, which is
mighty annoyin'.

Chris
Nov 15 '05 #1
4 1476
Hi Chris,

The UserControl has a Boolean property called DesignMode you can check.

--
Rob Windsor
G6 Consulting
Toronto, Canada
"Chris Capel" <ch***@ibanktech.net> wrote in message
news:uD*************@TK2MSFTNGP12.phx.gbl...
Is there any boolean flag set during design time that a UserControl can test to see whether to run code that only works during runtime (because of
complicated initialization)?

Like this:

public class MyControl : UserControl {
public MyControl() {
InitializeComponent();
if (!System.ComponentModel.Design.MagicClass.IsDesign Time)
DoSomethingUnsafeAtDesignTime();
}
}

Otherwise, I can't put my control on my form with the designer, which is
mighty annoyin'.

Chris

Nov 15 '05 #2
Well, DUH, Chris. How did you miss that?

Hehe.

Chris

"Rob Windsor" <rw******@NO.MORE.SPAM.bigfoot.com> wrote in message
news:uz**************@TK2MSFTNGP12.phx.gbl...
Hi Chris,

The UserControl has a Boolean property called DesignMode you can check.

--
Rob Windsor
G6 Consulting
Toronto, Canada

Nov 15 '05 #3
> The UserControl has a Boolean property called DesignMode you can check.

Strangely enough, this doesn't work at all. Example:

using System;
using System.Windows.Forms;

namespace Something {
public class MyUserControl : System.Windows.Forms.UserControl {
public MyUserControl() {
if (DesignMode)
MessageBox.Show("Hi, I'm in design mode.");
else
MessageBox.Show("Sorry, but no design mode :-(");
}
}
}

If you place this in a code file in a project, load the designer for it (to
register it with the design-time environment) and then try to drag it on a
form, it shows a message box saying "Sorry, but not design mode :-(".
Strange.

Chris
Nov 15 '05 #4
Hi Chris,

It appears that the property dosen't get set until after the constructor
completes. The container (in this case the form) has to interact with the
control's ISite interface and I'm not sure at what point of the control
construction phase that happens. Anyway, if you put your if statement in the
contol's Load event it will work properly.

--
Rob Windsor
G6 Consulting
Toronto, Canada
"Chris Capel" < > wrote in message
news:eI**************@TK2MSFTNGP10.phx.gbl...
The UserControl has a Boolean property called DesignMode you can check.
Strangely enough, this doesn't work at all. Example:

using System;
using System.Windows.Forms;

namespace Something {
public class MyUserControl : System.Windows.Forms.UserControl {
public MyUserControl() {
if (DesignMode)
MessageBox.Show("Hi, I'm in design mode.");
else
MessageBox.Show("Sorry, but no design mode :-(");
}
}
}

If you place this in a code file in a project, load the designer for it

(to register it with the design-time environment) and then try to drag it on a
form, it shows a message box saying "Sorry, but not design mode :-(".
Strange.

Chris

Nov 15 '05 #5

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

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
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...
98
by: Pamel | last post by:
I know this must have been asked elsewhere, but I cannot find it. There is a piece of text on my web page that I don't want browsers to resize. IE won't resize it if I specify the size in px, but...
10
by: BlueDolphin | last post by:
I'm not sure if this is a question or more of a rant... but I'm looking for some input on this from other developers out there. How often has the following happened to you and how have you dealt...
2
by: adb | last post by:
I came up with a replication configuration that is basically the result of all the restrictions of replication as well as the restrictions of allowable software on work PC's and I was curious if...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
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...
5
by: istillshine | last post by:
Particularly for medium-sized (10,000 ~ 20,000 lines) programs, what are useful strategies to design them before coding? My strategies are: 1. Imagine what the final program would look like....
4
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.