Search code examples
c#.netwinformspartial-classes

Assign event from partial class


I have made a winform application in c#. Now I added a class named Main_Form_1. In Main_Form, there are some click events that I copied in Main_Form_1.

// Main_Form.cs
public partial class Main_Form : Form
{
    ...
    // code here
    ...
}

// Main_Form_1.cs
public partial class Main_Form : Form
{
    private void SomeButton_Click(object sender, EventArgs e)
    {
        ...
    }
}

Now I want to assign this SomeButton_Click event, but I can not see the events in the property window. How can I assign this event to SomeButton?


Solution

  • I'm pretty sure you mean the event handler SomeButton_Click here. You can add it to the Click event of button "SomeButton" with: SomeButton.Click += SomeButton_Click;