Somewhere on _VisibleChanged event I am changing the ActiveControl:
private void ResultNumeric_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible)
{
this.ActiveControl = this.resNumResult;
}
}
Now if I follow one work flow of the program, my app is crashing. I looked at the StackTrace and it has a call to REMOVE in it which will set the Parent to null and actually crash is also coming from a place that I am calling a method on a a parent this is null.
at System.Windows.Forms.ContainerControl.AfterControlRemoved(Control control, Control oldParent)
at System.Windows.Forms.SplitContainer.AfterControlRemoved(Control control, Control oldParent)
at System.Windows.Forms.Control.ControlCollection.Remove(Control value)
So is it this change of ActiveControl that is causing the Remove method to be called?
I don’t think that setting the ActiveControl removes a control from form’s ControlCollection. The error must be somewhere else. Do you have a remove of a control somewhere else in your code?