繁体   English   中英

'MainFormLoad'的重载与委托'System.EventHandler'(CS0123)不匹配

No overload for 'MainFormLoad' matches delegate 'System.EventHandler' (CS0123)

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

我刚刚开始学习C#编程,但遇到了问题。 我做了一个简单的应用程序(只是一个带有两个按钮的窗口)。 一个按钮启动另一个程序,另一个按钮在2分钟内再次显示此窗口(这是一种提醒)。 没有X按钮,但仍可以由我要禁用的ALT F4关闭。

我已经尝试过e.Cancel = true; ,但显然我做错了。 我所做的是双击主窗口,然后代码中出现了void MainFormLoad(object sender, EventArgs e) ,然后将EventArgs e更改为FormClosingEventArgs并粘贴了上面的e.Cancel = true; FormClosingEventArgs 在那里。

我收到以下错误:

'MainFormLoad'的重载与委托'System.EventHandler'(CS0123)不匹配

它使我参考MainForm.Designer.cs中的这一行:

this.Load += new System.EventHandler(this.MainFormLoad);

这是整个代码:

using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Reminder
{
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
    {
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }
        int duration = 0;
        void Timer1Tick(object sender, EventArgs e)
        {
        duration++;
        System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo();
        start.FileName = @"C:\ThisProgram.exe";
        Process.Start(start);
        Application.Exit();
        if (duration == 1)
            {
            Timer.Stop();
            }
        }
        void LaterClick(object sender, EventArgs e)
        {
        Timer.Enabled = true;
        Timer.Start();
        Hide();
        }
        void OKClick(object sender, EventArgs e)
        {
        System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo();
        start.FileName = @"C:\OtherExternalProgram.exe";
        Process.Start(start);
        Application.Exit();
        }
        void MainFormLoad(object sender, FormClosingEventArgs e)
        {
        e.Cancel = true;
        }
    }
}

这是MainForm.Designer.cs代码:

namespace Reminder
{
    partial class MainForm
    {
        /// <summary>
        /// Designer variable used to keep track of non-visual components.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        private System.Windows.Forms.Button OK;
        private System.Windows.Forms.Timer Timer;
        private System.Windows.Forms.Button Later;

        /// <summary>
        /// Disposes resources used by the form.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                if (components != null) {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        /// <summary>
        /// This method is required for Windows Forms designer support.
        /// Do not change the method contents inside the source code editor. The Forms designer might
        /// not be able to load this method if it was changed manually.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.OK = new System.Windows.Forms.Button();
            this.Timer = new System.Windows.Forms.Timer(this.components);
            this.Later = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // OK
            // 
            this.OK.Location = new System.Drawing.Point(12, 253);
            this.OK.Name = "OK";
            this.OK.Size = new System.Drawing.Size(75, 23);
            this.OK.TabIndex = 0;
            this.OK.Text = "OK";
            this.OK.UseVisualStyleBackColor = true;
            this.OK.Click += new System.EventHandler(this.OKClick);
            // 
            // Timer
            // 
            this.Timer.Interval = 24000;
            this.Timer.Tick += new System.EventHandler(this.Timer1Tick);
            // 
            // Later
            // 
            this.Later.Location = new System.Drawing.Point(425, 253);
            this.Later.Name = "Later";
            this.Later.Size = new System.Drawing.Size(75, 23);
            this.Later.TabIndex = 1;
            this.Later.Text = "Later";
            this.Later.UseVisualStyleBackColor = true;
            this.Later.Click += new System.EventHandler(this.LaterClick);
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.Window;
            this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
            this.ClientSize = new System.Drawing.Size(512, 288);
            this.Controls.Add(this.Later);
            this.Controls.Add(this.OK);
            this.Cursor = System.Windows.Forms.Cursors.Default;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "MainForm";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.TopMost = true;
            this.Load += new System.EventHandler(this.MainFormLoad);
            this.ResumeLayout(false);

        }
    }
}

预先感谢您的帮助。

问题暂未有回复.您可以查看右边的相关问题.
2 C#CS0123:匹配委托Eventhandler没有重载

我在C#中为Android应用程序提供了以下代码 但后来我收到以下错误消息:'naam_textChanged没有重载匹配委托EventHandler 有谁知道如何解决这个问题? 问候,乔仁 ...

3 如何修复此错误 - C# CS0123:“方法”没有重载匹配委托“EventHandler”

我正在尝试将程序名称从我的表单传递给按钮单击事件。 但我不断收到以下错误消息: ““方法”没有重载匹配委托“EventHandler”” 我在这里阅读了类似的问题,并尝试了许多建议,但似乎没有解决我的具体问题。 我希望有人能告诉我我哪里出错了。 以下是我读过的一些帖子: “方法”没有重载匹 ...

2021-06-09 19:03:24 2 59   c#
10 没有匹配委托'system.eventhandler'的重载

因为我对C#很陌生,所以我很难接受以下代码。 当我点击按钮'knop'时,必须执行方法'klik'。 该方法必须在窗体上绘制由'DrawMandel'生成的位图'b'。 但我不断得到错误'没有重载的代理'system.eventhandler'。 ...

2011-09-26 08:35:10 4 132017   c#
暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2022 STACKOOM.COM