form1 :button1
form2:bt_ok,bt_cancle
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
if (form2.ShowDialog() == DialogResult.OK)
{
delete();
}
if (form2.ShowDialog() == DialogResult.Cancel)
{
}
}
private void delete()
{
MessageBox.Show("1");
}
public Form2()
{
InitializeComponent();
bt_ok.DialogResult = DialogResult.OK;
bt_cancle.DialogResult = DialogResult.Cancel;
}
private void bt_ok_keydown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
}
private void bt_cancle_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}