Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Control.FindForm and ContainerControl.ParentForm

I'm wondering if there is any functional (or otherwise) difference between Control.FindForm and ContainerControl.ParentForm? I've been using .ParentForm when creating my own user controls but would there be any reason .FindForm would be a better choice? From what I can tell, they would always return the same form (ie. the form the user control is on, or null). Is .ParentForm just calling .FindForm or is there a time where the two could be different (maybe with mdi windows)?

like image 299
TKTS Avatar asked Jul 22 '11 17:07

TKTS


1 Answers

They are subtly different. ParentForm will return null when you call it on a toplevel Form since it has no parent. FindForm() will not, it returns itself. And ParentForm makes a security demand, FindForm() does not. They otherwise use the same internal implementation. Winforms itself doesn't use ParentForm at all, I would ignore it.

like image 183
Hans Passant Avatar answered Sep 28 '22 05:09

Hans Passant