3

I have a parent form and a child form that inherits from the former. In design mode all the inherited controls' properties are disabled. How can I change these properties in the child form?

Here is a screenshot of the designer. Note how I have selected a text box and all its properties are disabled (greyed out).Screenshot

BJ Myers
  • 6,617
  • 6
  • 34
  • 50
user3646717
  • 1,095
  • 2
  • 12
  • 21
  • The controls defined in the parent are declared `private` by default, so they can't be edited in the designer of the child form. IIRC you can fix this by changing them to `protected` using the designer of the parent form. – BJ Myers Sep 09 '16 at 15:59
  • I did it, but it is not working. The child's control properties are still disabled. – user3646717 Sep 09 '16 at 16:05
  • Just tried it myself, and it's working for me. How did you change the controls to `protected`? Did you build afterwards? – BJ Myers Sep 09 '16 at 16:10
  • Now it works! I always thought that saving was usually enough for changes to take effect, I don't understand that... – user3646717 Sep 09 '16 at 16:14
  • Designer views tend to require a rebuild. I've noted that in my answer below. – BJ Myers Sep 09 '16 at 16:29
  • Off-topic, but to get most out of available space and better view of properties and designer, drag the properties windows and dock it to right side of visual studio. – Reza Aghaei Sep 09 '16 at 19:20

1 Answers1

4

By default, the Windows Forms designer creates components with the private access modifier. This means that an inheriting form will render the controls, but cannot modify them.

To fix this, open the base form in the designer. Select the control(s) that you want to be able to modify and change the Modifiers property to Protected.

Changing modifiers to protected

Important: After this change, you must rebuild the base form's project for changes to show up in the inheriting form's designer view.

BJ Myers
  • 6,617
  • 6
  • 34
  • 50
  • Thank you VERY much BJ Myers! – user3646717 Sep 09 '16 at 17:12
  • I was going crazy with this! I knew I had to change the modifier and even got it to work once. But couldn't reproduce it. It's that last "Important" step you mentioned that I was missing. Makes sense, in retrospect. Thanks. – ThermoX Oct 26 '19 at 03:30