How to Close Form using a custom button control.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to create a custom button control, and have the onclick event
close the form. I was thinking I would use this.Parent,Close() but close()
isn't in the drop down list. How can I do this?
 
that's because Parent is a Control not a form
you'll need to cast Parent to a form to call Close
 
Actually, the FindForm method seems to do the job.

protected override void OnClick( EventArgs e )
{
base.OnClick( e ) ;
Form form = (Form)this.FindForm();
form.Close();

}
 
Back
Top