SplitContainer ISupportInitialize 问题:VS2010 针对 .NET 3.5

发布于 2024-11-05 20:53:56 字数 608 浏览 0 评论 0原文

在 VS2010 中,我有一个针对 .NET Framework 4.0 的项目,然后必须恢复到目标 v.3.5。一旦发生这种情况,我拥有的 SplitContainer 对象将不会显示,并且实际上会抛出错误:“无法将类型为‘System.Windows.Forms.SplitContainer’的对象转换为类型为‘System.ComponentModel.ISupportInitialize’。”

现在,我做了一些挖掘,发现 3.5 实际上在 SplitContainer 上没有 ISupportInitialize,而在 .NET 4.0 中却有。我想我的问题是,如果我的目标是 3.5 但仍然遇到此问题,我该如何解决此问题?

重现问题的步骤:

  1. 在 Visual Studio 2010 中创建一个新的 C# Windows 窗体应用程序项目(确保面向 .NET Framework 4.0)
  2. 将拆分容器添加到基本窗体。
  3. 运行应用程序(将运行得很好)
  4. 将目标更改为 .NET Framework 3.5(属性->应用程序->目标框架:)
  5. 重新运行应用程序(它将因 Cast 异常而崩溃)。

任何对此的帮助将不胜感激!

In VS2010 I had a project targeting .NET Framework 4.0 and then had to revert to target v. 3.5. Once this happened, the SplitContainer object that I had will not display and will actually throw an error: "Unable to cast object of type 'System.Windows.Forms.SplitContainer' to type 'System.ComponentModel.ISupportInitialize'."

Now, I did some digging and found out that 3.5 does not, in fact, have ISupportInitialize on the SplitContainer and it does in .NET 4.0. I guess my question is, if I am targeting 3.5 and still getting this issue, how do i correct this?

Steps to reproduce problem:

  1. Create a new C# Windows Forms Application project in Visual Studio 2010 (Make sure to target .NET Framework 4.0)
  2. Add a split container to the basic form.
  3. Run the application (will run just fine)
  4. Change target to .NET Framework 3.5 (properties->Applications->Target Framework:)
  5. Rerun the application (It will crash with the Cast exception).

Any help with this would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

邮友 2024-11-12 20:53:56

我找到了这个问题的解决方案,它非常特别...如果您将表单回退到 3.5,则必须对程序中的每个表单进行一些小更改,以便编译器重新生成所有代码对于那种形式。我遇到问题的原因是因为我没有进行任何更改,并且正在尝试运行尚未重新生成的代码。

I found the solution to this problem and it was quite special... IF you backrev your forms to 3.5, you have to do a small change on EACH AND EVERY form you have in your program so that the compiler will regenerate all of the code for that form. The reason I was having an issue was because I had made no change and was trying to run the code, which had not been regenerated.

青瓷清茶倾城歌 2024-11-12 20:53:56

正如 @tomash 提到的,删除该特定控件上的 BeginInit() 和 EndInit() 行就足够了。

SplitContainer.BeginInit

.NET 框架
支持版本:4.5、4

单击 此处了解有关此方法的更多信息。

As @tomash mentioned to removes the line of BeginInit() and EndInit() on that specific control is enough.

SplitContainer.BeginInit

.NET Framework
Supported in: 4.5, 4

Click here for more info about this method.

荆棘i 2024-11-12 20:53:56

这是一篇旧文章,但我不喜欢每次都编辑设计器文件,这样会留下太多的错误空间。

我只是对控件进行了子类化,并使用预处理器指令实现了 .net 3.5 构建的接口,如下所示。

只是添加我的方法,因为这篇文章是在 2017 年寻找解决方案时出现的。

    /// <summary>
    /// Split Container Control
    /// </summary>
    public class SplitContainer : System.Windows.Forms.SplitContainer

#if (NET35)
        , ISupportInitialize
#endif

    {
        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        public SplitContainer() : base() { }

        #endregion Constructor

        #region ISupportInitialize Methods

#if (NET35)

        public void BeginInit() { }

        public void EndInit() { }

#endif

        #endregion ISupportInitialize Methods
    }

This is an old post but I did not like having to edit the designer files every time, leaves too much room for mistakes.

I just subclassed the control and implemented the interface for .net 3.5 builds as below using preprocessor directives.

Just adding my method as this post came up in 2017 when looking for a solution.

    /// <summary>
    /// Split Container Control
    /// </summary>
    public class SplitContainer : System.Windows.Forms.SplitContainer

#if (NET35)
        , ISupportInitialize
#endif

    {
        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        public SplitContainer() : base() { }

        #endregion Constructor

        #region ISupportInitialize Methods

#if (NET35)

        public void BeginInit() { }

        public void EndInit() { }

#endif

        #endregion ISupportInitialize Methods
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文