Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

c# - no overload for matches delegate 'system.eventhandler'

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());
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...