469,927 Members | 1,403 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

How to Close Form using a custom button control.

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?
Nov 17 '05 #1
2 1989
that's because Parent is a Control not a form
you'll need to cast Parent to a form to call Close
"Vern" <Ve**@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
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?

Nov 17 '05 #2
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();

}

"Alejandro Gonz√°lez" wrote:
that's because Parent is a Control not a form
you'll need to cast Parent to a form to call Close
"Vern" <Ve**@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
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?


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Reggie | last post: by
1 post views Thread by Vi | last post: by
5 posts views Thread by Stan Sainte-Rose | last post: by
9 posts views Thread by mohit.akl | last post: by
1 post views Thread by rn5a | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.