问题描述
由于我很新的C#,我用下面的一段代码斗争。当我点击按钮'杏花村',方法'的点击'已被执行。该方法具有绘制位图B,通过在表格上'DrawMandel'中产生。但我不断得到错误不超载火柴委托system.eventhandler
使用系统;使用System.Windows.Forms的
;
使用System.Drawing中;
类曼德尔布罗:表
{
公共位图B:
公共曼德尔布罗()
{
键杏花;
=杏花新的Button();
knop.Location =新的点(370,15);
knop.Size =新尺寸(50,30);
knop.Text =确定;
this.Text =曼德尔布罗1.0;
this.ClientSize =新的大小(800,800);
knop.Click + = this.klik;
this.Controls.Add(杏花村);
}
公共无效的点击(PaintEventArgs的豌豆,EventArgs五){
位图C = this.DrawMandel();
图形克= pea.Graphics;
gr.DrawImage(B,150,200);
}
公共位图DrawMandel()
{
//函数创建位图
回复B;
}
静态无效的主要(){
Application.Run(新曼德尔布罗());
}
}
您需要改变公共无效的点击(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
这篇关于无过载火柴委托“system.eventhandler”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!