User Control Question

Z

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
 
F

Flip

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.
 
S

Sahil Malik

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top