且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无过载火柴委托“system.eventhandler”

更新时间:2023-01-15 11:05:02

您需要改变公共无效的点击(PaintEventArgs的豌豆,EventArgs五)



公共无效的点击(对象发件人,发送System.EventArgs)



由于没有与参数 PaintEventArgs的豌豆,EventArgs的


As I'm pretty new to C#, I struggle with the following piece of code. When I click to button 'knop', the method 'klik' has to be executed. The method has to draw the Bitmap 'b', generated by 'DrawMandel' on the form. But I constantly get the error '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());
    }

}

You need to change public void klik(PaintEventArgs pea, EventArgs e) to

public void klik(object sender, System.EventArgs e)

because there is no Click event handler with parameters PaintEventArgs pea, EventArgs e