protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); if (CountParentControls() > MaximumNestingLevel) { //capture content, needed because it is set at a later time NestingLevelErrorControl errorControl = new NestingLevelErrorControl(() => Content, this.GetType()); errorControl.Dock = DockStyle.Fill; Controls.Clear(); Controls.Add(errorControl); } }