no overload for matches delegate 'system.eventhandler'

后端 未结 4 1252
天涯浪人
天涯浪人 2020-12-01 20:38

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 Bi

相关标签:
4条回答
  • 2020-12-01 21:06

    Change the klik method as follows:

    public void klik(object pea, EventArgs e)
    {
        Bitmap c = this.DrawMandel();
        Button btn = pea as Button;
        Graphics gr = btn.CreateGraphics();
        gr.DrawImage(b, 150, 200);
    }
    
    0 讨论(0)
  • 2020-12-01 21:10

    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.

    0 讨论(0)
  • 2020-12-01 21:12

    You need to wrap button click handler to match the pattern

    public void klik(object sender, EventArgs e)
    
    0 讨论(0)
  • 2020-12-01 21:28

    Yes there is a problem with Click event handler (klik) - First argument must be an object type and second must be EventArgs.

    public void klik(object sender, EventArgs e) {
      //
    }
    

    If you want to paint on a form or control then use CreateGraphics method.

    public void klik(object sender, EventArgs e) {
        Bitmap c = this.DrawMandel();
        Graphics gr = CreateGraphics();  // Graphics gr=(sender as Button).CreateGraphics();
        gr.DrawImage(b, 150, 200);
    }
    
    0 讨论(0)
提交回复
热议问题