title: C# - dll event handler
body: <p>I am setting a .dll file to create a new form and a new button, but i want that button to do something. Is it possible to create a event handler in a dll file?</p>
  
  <pre><code>public static byte sbuton( string er, int by,int re)
  {
      Form fg = new Form();
      fg.Show();
      Button b1 = new Button();
      fg.Controls.Add(b1);
      b1.Text = er;
      b1.Location = new Point(by, re);
      return 0;
  }
  </code></pre>
  
  <p>This is the code that creates a form with a button in it.
  When I try to create a new event handler, as I would in a form, I get this error: "An object reference is required for the non-static field, method or property".</p>
  
  <p><pre><code>
    public static byte sbuton( string er, int by,int re)
      {
          Form fg = new Form();
          fg.Show();
          Button b1 = new Button();
          fg.Controls.Add(b1);
          b1.Text = er;
          b1.Location = new Point(by, re);
          b1.Click += new EventHandler(b1_click);
      }</p>
  
  <p>private void b1_click(object sender , EventArgs e)
      {
      }
  </pre></code>
  This is the code from the form where I want use the dll</p>
  
  <p><pre><code>
  private void button1_Click(object sender, EventArgs e) 
  {
  if (richTextBox1.Text.Contains("add") &amp;&amp; richTextBox1.Text.Contains("buton") &amp;&amp; richTextBox1.Text.Contains("text"))
      {
          form.sbuton("buton", 10, 10);
      }
  }
  </pre></code>
  This creates a button, but nothing happens when the button is clicked, because no event handler is assigned to it in the .dll file.
  And also,sorry for the bad english,it is not my native language.</p>
  
  <p>What can i do?
   Thanks!</p>