public class MyForm : Form, IDoExit { public void DoExit() { MessageBox.Show("Closing Form via DoExit"); this.Close(); } } public class MyButton : Button { protected override void OnClick(EventArgs e) { base.OnClick(e); Form oForm = this.FindForm(); if (oForm is IDoExit) { ((IDoExit)oForm).DoExit(); MessageBox.Show("Click From Button Class"); } } }And from a button click event handler on your main form, create and open the dialog form:
private void btnOpenForm_Click(object sender, System.EventArgs e) { MyForm oForm = new MyForm(); MyButton btn = new MyButton(); oForm.Controls.Add(btn); oForm.ShowDialog(); }Click the button on the dialog form, it closes just fine and I have not done a thing with DialogResult.
public class MyButton : Button { protected override void OnClick(EventArgs e) { //base.OnClick(e); comment out, move to end of method Form oForm = this.FindForm(); if (oForm is IDoExit) { ((IDoExit)oForm).DoExit(); MessageBox.Show("Click From Button Class"); } base.OnClick(e); // now form will not close!!! } }I suspect the problem you were both seeing was where to put the call to the base.OnClick(e)!!