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 / Visual Studio.NET / IDE / March 2006

Tip: Looking for answers? Try searching our database.

VS.net shouldn't call custom control initializer!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
commanderjason@gmail.com - 27 Feb 2006 18:07 GMT
I have a recurring problem with the forms designer is VS.net 2003.

If you want to add a UserControl to your form, vs.net will call that
controls initialization code when placing the control in the form. I
believe this behavior only causes problems. I could care less if the
designer can initialize the control at design time as long as the
control works at runtime. I would be perfectly happy if the forms
designer just used a place holder for the control for the purpose of
placing and defining the visual behavior of the control.

The problem is that my controls require a bunch of resources to load,
one resource for example is the app.config file. I have many things in
the config file that my custom control has to load during the controls
initialization block. Internationalization settings, file paths,
perhaps db connection strings, the options are endless.

But as ive seen in the forms designer many resources such as the config
file, perhaps language and image resource files, are not available when
the control is loaded in the designer, only at runtime.

Therefore im forced to add all these try/catch blocks and generally
re-write my controls so the designer doesnt choke on something it
shouldn't need to do anyway.

Another annoyance of this behavior is that if i have my form is all
designed and setup, then i go and add some init code to the usercontrol
that uses some runtime resource such as the config file, the designer
will remove my control and basically erase the control and i have to
re-setup and size any and all controls that the designer deems unworthy
of running even though the code can and will execute flawlessly at
run-time.

Does anyone have any strategies that may prevent the designer from
running my control init code, or otherwise deal with this very annoying
problem?
George Jordanov Ivanov - 27 Feb 2006 23:57 GMT
Hi Jason,

You need to check the user control's DesignMode property - it is set to
true, if your control is in design-time mode, otherwise - false. Thus, the
initialize logic in your user control should be executed only if this
property is false.

Check out MSDN online for this specific property at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemcomponentmodelcomponentclassdesignmodetopic.asp


Regards,
George Jordanov Ivanov

>I have a recurring problem with the forms designer is VS.net 2003.
>
[quoted text clipped - 31 lines]
> running my control init code, or otherwise deal with this very annoying
> problem?
Jeff Pek (Autodesk) - 26 Mar 2006 12:33 GMT
The only problem is that this property doesn't always return the correct
value. There are many blog, etc. posts on this. Apparently this still has
not been fixed in VS2005.

Here's one of many blog posts that talks about this:
http://blogs.vbcity.com/hotdog/archive/2005/10/21/5596.aspx

It makes a couple of points about its use, and suggests some alternatives
that are more reliable.

Jeff

> Hi Jason,
>
[quoted text clipped - 44 lines]
>> running my control init code, or otherwise deal with this very annoying
>> problem?

Rate this thread:







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.