0
votes

I have a basic form that almost all forms inherit from it and this basic form have 7 buttons (so all "child" forms have it)

it all worked fine but today I'm getting this error on all inherited buttons the error is

An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll

Additional information: 'child' is not a child control of this parent.

on inherited buttons

 this.Controls.SetChildIndex(this.button, 0);

in the auto generated code in the designer.cs

I didn't change a bit in the base form designer since yesterday

I have tried to create new buttons with the same name - did not help and when I comment the relevant line, the button don't response

1
add the error to the question please. - Samvel Petrosov
Sorry, edited question - styx

1 Answers

0
votes

I faced similar issue as in this old question. Recording it here if someone else faces the same.

As the error messages suggests

Additional information: 'child' is not a child control of this parent.

The scenario is that you have inherited a form, but button control is missing from child form's Controls collection while calling

this.Controls.SetChildIndex(this.button, 0);

In this case property button should be added to the Controls collection by the base form and the primary fix is to identify the bug why the control is missing and fix it.

If that is not possible, for some reason, secondary solution is to add missing property on Controls collection in your inherited form before calling designer generated code. No modification should be made in designer generated code as that will be overwritten anyway in the future.