I have a little question (intellectual curiosity), I have noticed that if a control (of a form) is declared as private and create it dinamically, you can access outside the class with FindComponent.
Is it logically correct?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That happens because when the control is created, it registers itself into its owners list of owned components. And hence there are multiple references to the control.
The reference to the control in the form’s class is indeed private. But the reference to the control that the form holds in its Components list is public.
Logically this is very similar to exposing the private variable through a property:
Although you don’t directly expose the private field like this, the control does so indirectly by registering with the owning form.