How do I keep Visual Studio's Windows Forms Designer from deleting controls?
Posted
by Sören Kuklau
on Stack Overflow
See other posts from Stack Overflow
or by Sören Kuklau
Published on 2010-04-20T18:32:16Z
Indexed on
2010/04/20
18:33 UTC
Read the original article
Hit count: 601
With several forms of mine, I occasionally run into the following issue: I edit the form using the designer (Visual Studio 2008, Windows Forms, .NET 2.0, VB.NET) to add components, only to find out later that some minor adjustments were made (e.g. the form's size is suddenly changed by a few pixels), and controls get deleted. This happens silently — event-handling methods automatically have their Handles
suffix removed, too, so they never get called, and there's no compiler error. I only notice much later or not at all, because I'm working on a different area in the form.
As an example, I have a form with a SplitContainer
containing an Infragistics UltraListView
to the left, and an UltraTabControl
to the right. I added a new tab, and controls within, and they worked fine. I later on found out that the list view's scrollbar was suddenly invisible, due to its size being off, and at least one control was removed from a different tab that I hadn't been working on.
Is this a known issue with the WinForms Designer, or with Infragistics? I use version control, of course, so I can compare the changes and merge the deleted code back in, but it's a tedious process that shouldn't be necessary. Are there ways to avoid this? Is there a good reason for this to occur?
One clue is that the control that was removed may have code (such as a Load
event handler) that expects to be run in run time, not design time, and may be throwing an exception. Could this cause Visual Studio to remove the control?
© Stack Overflow or respective owner