Jump to content
  • Advertisement
Sign in to follow this  
Telamon

[.net] Form designer keeps deleting my control :-(

This topic is 4880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using C# with VS 2003 Enterprise Architect and I've got a user control that I wrote which displays a tilemap using DirectX (but it doesn't create a D3D device until runtime). I've got an instance of this control drawn on my main form. Every so often when I open the project file, I find that the IDE has deleted the user control from my form. Everything works if I redraw it back on but it's driving me crazy. Anyone had a problem like this before?

Share this post


Link to post
Share on other sites
Advertisement
I've had similar designer problems that were solved by closing and re-opening Visual Studio. Having the files under source control is also very helpful when the Form Designer is screwing you over, since having the file as read-only will prevent the problem from being saved on your hard drive.

Share this post


Link to post
Share on other sites
Quote:
Original post by _DarkWIng_
My co-worker had this problem with some user created controls. His "solution": Don't open form in design mode.


The .Net design time features are pretty cool, so totally avoiding the designer is not really the best solution imo. I've had the problem a couple of times, but I was always able to find the reason.

Sometimes the reason was that the Designer was trying to set Properties (public read/write properties are serialized by default) that weren't meant to be set at design time because certain resources (or whatever) are only available at run time.

In that case you could either check the Control.DesignTime Property (available after the Control has been loaded) and do things differently at design time.

If the Property should not be serialized at all, you can mark it with [DesignerSerializationVisiblity(DesignerSerializationVisibility.Hidden)].

Another option to control serialization is to add a bool property "ShouldSerializeMyProperty", where MyProperty is replaced with the property's name.

Checking the code paths of the Control is a good idea too (Controls in the Designer are created through their public default constructors). Finally, you can use an other instance of VS.Net to debug your design time code. See here.

One last thing, while you're working on the control's code, it's a very good idea to not keep any Forms that are using the Control open in the designer while compiling.

Share this post


Link to post
Share on other sites
Quote:
Original post by itachi
In that case you could either check the Control.DesignTime Property (available after the Control has been loaded) and do things differently at design time.


One word of warning though: the DesignTime property does NOT work in the constructor (which makes sense: it is set by the designer AFTER the instance is created).

There are other tricks that work in the c'tor, but I don't remember them at the moment. Just googling a bit should bring them up.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!