468,133 Members | 1,527 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

User Control Question

Z D
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
it gives an error saying that the file doesn't exist.

Obviously the file doesnt exist yet because its only created at runtime!!

So, why is the design-time environment (VS.NET 2003) trying to compile my
app when I load the user control onto the winform?

Anyways - if I comment out references to this file in the control then I can
add it with no problems to the winform.

My question is: How do I disable this functionality so that Visual Studio
doesnt try to "be too smart" during design time?

Thanks!
-ZD
Nov 16 '05 #1
3 2097
> My question is: How do I disable this functionality so that Visual Studio
doesnt try to "be too smart" during design time?

I'm just getting into this c# stuff so I might be a bit off the mark here,
but instead of having disabling VS designtime functionality, why not have
your code itentify runtime vs design time and not do your file check at
design time? Would that work? I came from java/JB and that's how javabeans
are usually done for these problems. Good luck.
Nov 16 '05 #2
ZD,

The IDE in a way needs to run the constructor to do all the control specific
renderings to make the control look like as close to possible as it would in
realtime. So if in your constructor you drew a blue line across the control,
the control will draw the blue line on itself in the designer only by
calling the default constructor. Basically you want to stay away from the
default constructor, InitializeComponent and the "load" event for this
purpose.

You can implement a non-default constructor (one that will take parameters)
to get around this issue.

Also there is a "DesignMode" property on the control - probably won't work
in your case because DesignMode is always false in the constructor.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
Please reply to the newsgroups instead of email so everyone can benefit from
your reply.
"Z D" <no****@nospam.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
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 it gives an error saying that the file doesn't exist.

Obviously the file doesnt exist yet because its only created at runtime!!

So, why is the design-time environment (VS.NET 2003) trying to compile my
app when I load the user control onto the winform?

Anyways - if I comment out references to this file in the control then I can add it with no problems to the winform.

My question is: How do I disable this functionality so that Visual Studio
doesnt try to "be too smart" during design time?

Thanks!
-ZD

Nov 16 '05 #3
I realize this solution is probably considered crude, but when nothing else
works, including the use of a separate thread, it can be useful.

At the end of the Constructor, start a timer, with the increment setting at
200 (you can probably shorten that if this works for you) . In the tick
event of the timer, Stop the timer on the first line of code. Then test
whether the code is processing in design time with me.designtime. If not,
the code is processing in runtime, you can get the file and process it in the
timer event handler.

Note: You can add a messagebox while you're testing this to show that the
code after "If me.designmode = false then" is not running in design time. As
another poster on this thread pointed out me.designmode is always false in
the Constructor. In the timer, however, it is set according to the current
mode.

www.charlesfarriersoftware.com
"Z D" wrote:
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
it gives an error saying that the file doesn't exist.

Obviously the file doesnt exist yet because its only created at runtime!!

So, why is the design-time environment (VS.NET 2003) trying to compile my
app when I load the user control onto the winform?

Anyways - if I comment out references to this file in the control then I can
add it with no problems to the winform.

My question is: How do I disable this functionality so that Visual Studio
doesnt try to "be too smart" during design time?

Thanks!
-ZD

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Lloyd Sheen | last post: by
6 posts views Thread by Jim Heavey | last post: by
8 posts views Thread by Prince Mathew | last post: by
reply views Thread by campwes | last post: by
reply views Thread by Brian Cesafsky | last post: by
reply views Thread by Brian Cesafsky | last post: by
1 post views Thread by weboweb | last post: by
4 posts views Thread by =?Utf-8?B?UmljaEI=?= | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.