private EditModSearch AddSearch() { SuspendLayout(); var ctl = new EditModSearch() { // Dock handles the layout for us Dock = DockStyle.Top, ShowLabel = editors.Count < 1, TabIndex = editors.Count * 2 }; ctl.ApplySearch += EditModSearch_ApplySearch; ctl.SurrenderFocus += EditModSearch_SurrenderFocus; editors.Add(ctl); Controls.Add(ctl); // Docked controls are back at top, front at bottom, so send to bottom ctl.BringToFront(); // Still need to be able to see the add button, without this it's covered up AddSearchButton.BringToFront(); Height = editors.Sum(ems => ems.Height); ResumeLayout(false); PerformLayout(); return(ctl); }
private void EditModSearch_ApplySearch(EditModSearch source, ModSearch what) { if (what == null && editors.Count > 1) { RemoveSearch(source); } Apply(); }
private void RemoveSearch(EditModSearch which) { if (editors.Count >= 2) { if (which == ActiveControl) { // Move focus to next control, or previous if last in list var activeIndex = editors.IndexOf(which); ActiveControl = activeIndex < editors.Count - 1 ? editors[activeIndex + 1] : editors[activeIndex - 1]; } editors.Remove(which); Controls.Remove(which); // Make sure the top label is always visible editors[0].ShowLabel = true; Height = editors.Sum(ems => ems.Height); } }