views:

42

answers:

1

Why is it that some components/controls will not be inherited visually in a child form if they are declared with the access modifier Friend vs when they are declared with Protected.

For example, I've got a DataSet object in my Parent Form that was initially "Friend" (I drag and dropped it to the form, so it was shown as a control in the designer view), but I noticed that my Child Form did not inherit the control as expected. Once I changed it to "Protected", it showed up in my Child form as expected.

I am aware that Protected allows the Child Form to modify the inherited control, but how exactly does this tie in to the issue I described above?

+1  A: 

It depends on the assembly in which the base form is declared. If that's another assembly than the one in which the derived form lives then Friend cannot work. Members declared Friend are only accessible inside the same assembly.

Protected is the proper access modifier here. It ensures that it doesn't matter in what assembly the derived form is declared. And ensures that only derived form classes can access the dataset.

Hans Passant