How to get Visual Studio Windows Forms Designer to remove controls?

With several of my methods, I sometimes encounter the following problem: I edit the form using the constructor (Visual Studio 2008, Windows Forms, .NET 2.0, VB.NET) to add components, only to find out later that some minor adjustments have been made ( for example, the size of the form suddenly changes by a few pixels), and the controls are deleted. This happens silently - event processing methods automatically also remove the suffix Handles, so they are never called, and there is no compiler error. I only notice much later or not at all because I work in a different field in the form.

As an example, I have a form c SplitContainercontaining Infragistics UltraListViewon the left, and UltraTabControl- on the right. I added a new tab and controlled it, and they worked perfectly. Later, I found out that the scrollbar of the list was unexpectedly invisible due to the fact that its size was turned off and at least one control was removed from another tab that I did not work on.

Is this a known issue with WinForms Designer or with Infragistics? Of course, I use version control, so I can compare the changes and combine the remote code, but this is a tedious process that should not be necessary. Are there any ways to avoid this? Is there a good reason for this?

One key is that the remote control can have code (such as an event handler Load) that is expected to be run at run time, rather than development time, and can throw an exception. Can Visual Studio remove a control?

+3
source share
6 answers

This is not the answer to your question, but remember that you should use "DesignMode" in loads. This avoids unexpected behavior during development.

private void EureFormAbm_Load(object sender, System.EventArgs e)
{
    if (!DesignMode)
    {
        // Your code
    } /* if */
}

or

private void EureFormAbm_Load(object sender, System.EventArgs e)
{
    if (DesignMode)
        return;
    // Your code
}
+10
source

, , . Visual Studio "Tools- > Attach to Process" . , . (, ) .

+2

, , .

) . @ . , , , -UI ( ) Form_Load. , , .

B) -:

.cs Windows Forms.

, , . , , , . - , , -, .cs. , .

C) , , IDE, ? " ", .

Windows Forms , , , , , , DesignMode, , . -, , , designer.cs .

+1

, DesignMode ( ). , ( , , ), "" , , , DesignMode .

    /// <summary>
    /// Indicates if the current view is being utilized in the VS.NET IDE or not.
    /// </summary>
    /// <remarks>The DesignMode property for a UserControl object will show that it is in DesignMode
    /// only if the immediate parent is viewed in the IDE; if it is a grand child of the object that is being viewed in the IDE,
    /// then the DesignMode property will not be true.
    /// This is a workaround</remarks>
    public bool InDesignMode
    {
        get
        {
            // Site.Design mode sometimes produces a better result.
            if (DesignMode || Site != null && Site.DesignMode)
                return true;
            Control parent = Parent;
            while (parent != null)
            {
                if (parent.Site != null && parent.Site.DesignMode)
                    return true;
                parent = parent.Parent;
            }

            // Note: I am not 100% sure about this one; I need to double check
            // if in design mode then entryAssembly will be null. This check is 
            // needed because DesignMode property is only true for the control
            // that is actively being designed, so child controls will be false...
            // We do check the Parent heirarchy in InDesignMode but in some 
            // cases Parent will not be set before the check is required.
            var entryAssembly = Assembly.GetEntryAssembly();
            if (entryAssembly == null)
                return true;

            return false;
        }
    }
+1

, Visual Basic 6.0 .NET, . .

0

, . IDE , . .

0
source

Source: https://habr.com/ru/post/1741986/


All Articles