因为我对C#很陌生,所以我与下面的一段代码纠缠在一起。当我点击按钮'knop'时,必须执行'klik'方法。该方法必须在窗体上绘制由'DrawMandel'生成的位图'b'。但我总是得到错误'没有超载匹配委托'system.eventhandler'。没有超载的匹配委托'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());
}
}
事件处理程序委托有一个'对象发件人,EventArgs e'参数列表。你的不是。对于记录,我怀疑'Click'事件会有'PaintEventArgs'。 – BoltClock
看起来您已将OnPaint()方法重命名为klik,然后尝试将其连接到按钮事件处理程序。除去+ = klik赋值,并从窗体设计器中双击该按钮,它将创建一个新的Button处理程序。 – StuartLC
这是试错法编程。会有更多的错误,你不能只画一个位图,并希望它幸存下来。访问您当地的图书馆并查看Winforms编程手册。 –