DialogResult property of clicked button set to result from ShowDialog.
namespace WinFormsApp1
{
using System;
using System.Windows.Forms;
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form subform = new Form() { Width = 200, Height = 100, FormBorderStyle = FormBorderStyle.FixedToolWindow };
{
Button yesButton = new Button() { Text = "&Yes" };
yesButton.DialogResult = DialogResult.Yes;
Button noButton = new Button() { Text = "&No" };
noButton.DialogResult = DialogResult.No;
noButton.Left = yesButton.Width + 5;
subform.Controls.Add(yesButton);
subform.Controls.Add(noButton);
}
DialogResult result = subform.ShowDialog();
switch (result)
{
case DialogResult.Yes:
// your database code here
this.Close();
break;
case DialogResult.No:
break;
default:
break;
}
}
}
}