Winforms 用户控件 MissingMethodException [英] Winforms User Control MissingMethodException

查看:24
本文介绍了Winforms 用户控件 MissingMethodException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个名为 ExcelDisplay 的自定义用户控件.我尝试将它从工具箱中的 Visual Studio 拖到同一个项目中的网络表单中,但我得到了一个丢失的方法异常.有一次构造函数是参数化的,但我在认为这是一个糟糕的设计想法后改变了它.

So essentially, I have a custom user control called ExcelDisplay. I try to drag it over in visual studio from the toolbox into my webform in the same project and I get a missing method exception. At one time the constructor was parameterized, but I changed it after deciding it was a bad design idea.

看起来好像是说缺少构造函数,但它显然存在.

It looks like it is saying the constructor is missing, but its obviously there.

我用来放置控件的 winform 是空的,除了 Visual Studio 放置在那里的自动生成代码.

My winform to house the control is empty with the exception of the autogenerated code visual studio puts there.

我的 ExcelDisplay 构造函数的代码如下所示.

The code for my ExcelDisplay's constructor looks like this.

    namespace STS_Console.UserControls
    {
        public partial class ExcelDisplay : UserControl
        {

            public ExcelDisplay()
            {
                InitializeComponent();

                DataDisplay.Columns[0].HeaderText = "Data";
                //debug
                string x = DataDisplay.Columns[0].GetType().ToString();
                x.ToString();
            }

错误信息是这样的.

所以当我像这样拖放设计器时会发生该错误

So that error occurs when do I drag and drop in the designer like this

无论如何,这是我的问题.我不确定是什么导致了它或如何修复它.我很乐意应要求发布其他代码.

Anyway so that is my problem. I am not sure what is causing it or how to fix it. I would be glad to post additional code upon request.

推荐答案

您应该将您的用户控件放在它们自己的类库中.为了让设计器工作,它需要一个编译版本的用户控件.如果您不能在编译表单之前编译您的用户控件,您将遇到各种麻烦.

You should put your user controls in a class library of their own. For the designer to work, it needs a compiled version of your user control. If you cannot compile your user control before you compile your form, you will get into all kinds of trouble.

这篇关于Winforms 用户控件 MissingMethodException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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