1. ホーム
  2. c#

[解決済み] matches delegate 'system.eventhandler' のオーバーロードがありません。

2022-02-28 22:40:17

質問

私はC#の初心者なので、次のようなコードに苦労しています。ボタン'knop'をクリックすると、メソッド'klik'が実行されなければならない。このメソッドは、'DrawMandel'によって生成されたビットマップ'b'をフォームに描画しなければならない。しかし、「no overload for matches delegate 'system.eventhandler'」というエラーが常に発生します。

using System;
using System.Windows.Forms;
using System.Drawing;

class Mandelbrot : Form 
{
    public Bitmap b;
    public Mandelbrot() 
    {
        Button knop;
        knop = new Button();        
        knop.Location = new Point(370, 15);        
        knop.Size = new Size(50, 30);
        knop.Text = "OK";        

        this.Text = "Mandelbrot 1.0";
        this.ClientSize = new Size(800, 800);
        knop.Click += this.klik;
        this.Controls.Add(knop);        


    }
    public void klik(PaintEventArgs pea, EventArgs e) {
        Bitmap c = this.DrawMandel();
        Graphics gr = pea.Graphics;
        gr.DrawImage(b, 150, 200);
    }
    public Bitmap DrawMandel()
    {
        //function that creates the bitmap
        return b;
    }
    static void Main() {
        Application.Run(new Mandelbrot());
    }

}

解決方法は?

を変更する必要があります。 public void klik(PaintEventArgs pea, EventArgs e) から public void klik(object sender, System.EventArgs e) がないため Click イベントハンドラで、パラメータ PaintEventArgs pea, EventArgs e .