Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...