【发布时间】:2018-03-02 14:10:58
【问题描述】:
当我在 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继承表单FormBase。
在设计器中是这样的:
this.button6.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dragScreen_MouseDown);
【问题讨论】:
-
请出示代码
-
我不知道要显示什么,因为方法本身不是问题。只是似乎不喜欢它的设计师。我在这里发现了类似的问题,但没有用:stackoverflow.com/questions/3165269/…
-
所以你添加了一个像
class FormBase : Form1这样的新类? -
用'new'关键字声明方法,或重命名方法。