派生方法的 C# 设计器错误



我在Visual Studio中为我的窗体打开设计器时遇到问题

方法"dragScreen_MouseDown"不能是事件的方法,因为此类派生自的类已经定义了该方法。

我唯一改变的是添加一个名为 FormBase 的新类,并将该类的方法获取到其他形式。工作正常,但设计师似乎不喜欢它。

所以在FormBase.cs我得到了这种方法:

protected void dragScreen_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture();
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }
}

然后在Main.cs继承表单库。

在设计器中是这样的:

this.button6.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dragScreen_MouseDown);
我认为

您的问题是您从类BaseForm派生了MainForm,而偏部分类是从类System.Windows.Forms.Form派生的。这意味着设计器生成的代码我从类System.Windows.Forms.Form派生,但你的类部分是BaseForm。您需要将设计器代码从 public partial class MainForm : Form 更改为 public partial class MainForm : BaseForm

我说的对吗??

我能够解决问题。由于我在 Main.Designer 中有 dragScreen.cs这导致了第一个冲突,它不喜欢在类之外寻找方法。所以我不得不删除这些行并添加 Main.cs 构造函数:

panel4.MouseDown += dragScreen_MouseDown;

相关内容

最新更新