如何保持Visual Studio的Windows窗体设计器从删除的控制? [英] How do I keep Visual Studio's Windows Forms Designer from deleting controls?

查看:177
本文介绍了如何保持Visual Studio的Windows窗体设计器从删除的控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过多种形式我的,我偶尔会碰到以下问题:我使用设计器(Visual Studio 2008中,Windows窗体,.NET 2.0,VB.NET)添加组件编辑的形式,后来才发现,一些小的调整作了(如表的大小是由几个像素突然改变),并控制被删除。出现这种情况默默地 - 事件处理方法自动拥有自己的手柄的后缀去掉,也一样,所以他们从来没有被调用,而且也没有编译器错误。我只注意到晚得多或根本没有,因为我的工作在不同的区域的形式。

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.

作为一个例子,我有一个的SplitContainer 包含Infragistics的 UltraListView 向左,和形式 UltraTabControl 的权利。我添加了一个新的选项卡,并在控制,他们工作得很好。我后来发现,列表视图的滚动条突然看不见的,因为它的大小被关闭,并从不同的标签,我没有一直在辗转至少一个控制。

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.

这是一个已知问题的WinForms设计师,或者与Infragistics的?我使用的版本控制,当然,这样我可以比较的变化,早在合并中删除code,但它是一个繁琐的过程,不应该是必要的。是否有办法避免这种情况?是否有这种情况发生一个很好的理由?

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?

一个线索就是被删除,可能有code中的控件(如加载事件处理程序),其预计将在运行时间上运行,而不是设计时间,并且可以抛出异常。难道这导致Visual Studio中删除控制?

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?

推荐答案

这是不是一个回答你的问题,但要记住,你应该在加载使用的designMode。这在设计时避免怪异的意外行为。

This is not an answer to your question, but remember that you should use "DesignMode" in loads. This avoids weird unexpected behaviors during design time.

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

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

这篇关于如何保持Visual Studio的Windows窗体设计器从删除的控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆