4 Replies - 593 Views - Last Post: 28 April 2014 - 05:40 AM Rate Topic: -----

#1 vishavajeet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 22-April 14

how to access user control from child form

Posted 22 April 2014 - 05:15 AM

I hav created mdi parent form that contain one user control.
I want to access that user control from one of the child form
Is This A Good Question/Topic? 0
  • +

Replies To: how to access user control from child form

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,115
  • Joined: 05-May 12

Re: how to access user control from child form

Posted 22 April 2014 - 05:45 AM

The hack solution: Make the control public.

The real solution: You shouldn't. You are breaking object oriented SOLID principles when you do this. You should pause to consider why you need access to the control. Do you need the control because you need the value stored in that control? If so, then you are incorrectly using the control for data storage when instead you need to have a data model that is given to the MDI form and updated by the form.
Was This Post Helpful? 2
  • +
  • -

#3 vishavajeet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 22-April 14

Re: how to access user control from child form

Posted 22 April 2014 - 08:58 PM

View PostSkydiver, on 22 April 2014 - 05:45 AM, said:

The hack solution: Make the control public.

The real solution: You shouldn't. You are breaking object oriented SOLID principles when you do this. You should pause to consider why you need access to the control. Do you need the control because you need the value stored in that control? If so, then you are incorrectly using the control for data storage when instead you need to have a data model that is given to the MDI form and updated by the form.

Was This Post Helpful? 0
  • +
  • -

#4 vishavajeet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 22-April 14

Re: how to access user control from child form

Posted 22 April 2014 - 09:04 PM

I am not doing any data operation on user control.
I just want to use its Visible Property .
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,115
  • Joined: 05-May 12

Re: how to access user control from child form

Posted 28 April 2014 - 05:40 AM

You should expose a property that exposes it. Something like IsMyControlNameVisible. This is to follow the Law of Demeter.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1