Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

User Control Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Z D - 26 Oct 2004 18:52 GMT
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
Flip - 26 Oct 2004 19:02 GMT
> 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.
Sahil Malik - 26 Oct 2004 19:12 GMT
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.

> Hello,
>
[quoted text clipped - 17 lines]
> Thanks!
> -ZD
Charlie - 27 Oct 2004 01:15 GMT
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

> Hello,
>
[quoted text clipped - 17 lines]
> Thanks!
> -ZD

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.