Assuming WinForms, there are several approaches you could take. You can open each button as a property in your form class and have a class that creates a form for subscribing to the Click event for each button. For instance,
In the Form class:
public class MyForm : Form
{
public Button Button1
{
get { return button1; }
}
}
In the class that creates the form:
public class MyClass
{
public Form CreateForm()
{
var form = new MyForm();
form.Button1.Click += HandleButton1Clicked;
return form;
}
private void HandleButton1Clicked(object sender, EventArgs e)
{
}
}
Alternatively, you can add the ButtonClicked event to the form and determine which button was clicked that way. The form will be subscribed to each of its buttons. Click "Events" and click the "ButtonClicked" button with the button as the sender.
I will probably go with the first one, as this will not allow the if statement to be written to determine which button was pressed.
Edited to adapt to the workflow in the comments:
, , , . , , . , , , .
public class MyForm : Form
{
private Button button1;
private Button button2;
public MyForm()
{
InitializeComponent();
button1.Click += HandleButtonClicked;
button1.DialogResult = DialogResult.OK;
button2.Click += HandleButtonClicked;
button2.DialogResult = DialogResult.OK;
}
private void HandleButtonClicked(object sender, EventArgs e)
{
ButtonClicked = sender as Button;
}
public Button ButtonClicked
{
get; private set;
}
}
:
public class MyClass
{
public int GetValue()
{
var form = new MyForm();
if(form.ShowDialog() == DialogResult.OK)
{
}
else
{
}
}
}
, HandleButtonClicked , , .