由于我对 C# 还很陌生,所以我很难理解下面的代码。当我单击“knop”按钮时,必须执行“klik”方法。该方法必须在表单上绘制由“DrawMandel”生成的位图“b”。但我不断收到错误“匹配委托‘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)
to public void klik(object sender, System.EventArgs e)
因为没有Click
带参数的事件处理程序PaintEventArgs pea, EventArgs e
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)