Winforms User Control MissingMethodException

核能气质少年 提交于 2020-01-05 09:28:14

问题


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.

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

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();
            }

The error message is this.

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.


回答1:


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.




回答2:


Rebuild Solution fixed it for me, although if your making regular changes to your user control, you should put them into a separate project.

My particular problem, was a user control, within a user control.



来源:https://stackoverflow.com/questions/24594348/winforms-user-control-missingmethodexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!