[英]C# Is it possible to convert EventArgs to FormClosingEventArgs when calling method in a method?
[英]Why is there an error when i change argument of "EventArgs" to "FormClosingEventArgs"
在 Program.cs 中,Argument EventArgs更改为FormClosingEventArgs
private void Exit_Click(object sender, FormClosingEventArgs e) { }
在Program.Designer.cs,变化的Program.cs导致在Line.9错误
private void InitializeComponent()
{
this.Exit = new System.Windows.Forms.Button();
this.SuspendLayout();
this.Exit.Location = new System.Drawing.Point(839, 275);
this.Exit.Name = "Exit";
this.Exit.Size = new System.Drawing.Size(169, 112);
this.Exit.TabIndex = 0;
this.Exit.Text = "Exit";
this.Exit.UseVisualStyleBackColor = true;
this.Exit.Click += new System.EventHandler(this.Exit_Click); //ErrorPart
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1020, 399);
this.Controls.Add(this.Exit);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
Exisi 错误 CS0123:“Exit_Click”没有重载匹配委托“EventHandler”。
每次我开始调试时都会向我显示,我使用的是 Visual Studio 2017,那边有什么问题......?
这是因为System.Windows.Forms.Control
的Click
处理程序不采用FormClosingEventArgs
类型的FormClosingEventArgs
,而是采用需要像这样传递的EventArgs
private void Exit_Click(object sender, EventArgs e) { }
简单来说,这就像将一个
string
值分配给一个int
变量
有关更多信息,请参阅此 - https://msdn.microsoft.com/en-us/library/system.windows.forms.control.click(v=vs.110).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.