private void RemoveEditFormUICustomisations(EditAutoTypeItemForm editForm) { var extraControls = editForm.Controls.Find(ExtraControlsName, false).FirstOrDefault(); var container = editForm.Controls.Find(ExistingControlsContainerName, false).FirstOrDefault(); if (extraControls == null || container == null) { Debug.Fail("Form not customised"); return; } editForm.SuspendLayout(); try { var acceptButton = editForm.AcceptButton; var cancelButton = editForm.CancelButton; var shiftAmount = extraControls.Height; editForm.Controls.Remove(container); editForm.Controls.Remove(extraControls); if (editForm.MinimumSize.Height != 0) { editForm.MinimumSize = new Size(editForm.MinimumSize.Width, editForm.MinimumSize.Height - shiftAmount); } editForm.Height -= shiftAmount; foreach (var control in container.Controls.Cast <Control>().ToArray()) { editForm.Controls.Add(control); } container.Dispose(); extraControls.Dispose(); editForm.AcceptButton = acceptButton; editForm.CancelButton = cancelButton; } finally { editForm.ResumeLayout(); } }
private void CustomiseEditFormUI(EditAutoTypeItemForm editForm) { if (editForm.Controls.Find(ExtraControlsName, false).Any()) { Debug.Fail("Form already customised"); return; } var editSequenceOnlyField = typeof(EditAutoTypeItemForm).GetField("m_bEditSequenceOnly", BindingFlags.Instance | BindingFlags.NonPublic); if (editSequenceOnlyField != null) { if (editSequenceOnlyField.GetValue(editForm) as bool? == true) { // This is a sequence-only edit window, so don't customise it. return; } } editForm.SuspendLayout(); try { var banner = editForm.Controls.Find("m_bannerImage", false).FirstOrDefault(); var placeholders = editForm.Controls.Find("m_rtbPlaceholders", false).FirstOrDefault(); // Add the new control, docked just below the banner var extraControls = new EditAutoTypeExtraControls(editForm) { Name = ExtraControlsName, Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right, AutoSizeMode = AutoSizeMode.GrowOnly, }; editForm.Controls.Add(extraControls); editForm.Controls.SetChildIndex(extraControls, 0); if (banner != null) { extraControls.Top = banner.Bottom; extraControls.MinimumSize = new Size(banner.Width, 0); } var shiftAmount = extraControls.Height; // Move all existing controls, except for the banner and the extra controls, into a container var container = new Panel { Name = ExistingControlsContainerName, Size = editForm.ClientSize, Location = Point.Empty, Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom, }; var acceptButton = editForm.AcceptButton; var cancelButton = editForm.CancelButton; foreach (var control in editForm.Controls.Cast <Control>().ToArray()) { if (control != banner && control != extraControls) { container.Controls.Add(control); } } editForm.AcceptButton = acceptButton; editForm.CancelButton = cancelButton; if (editForm.FormBorderStyle == FormBorderStyle.Sizable) { ApplyKeeResizeHack(editForm, shiftAmount); } // Resize the form editForm.Height += shiftAmount; if (editForm.MinimumSize.Height != 0) { editForm.MinimumSize = new Size(editForm.MinimumSize.Width, editForm.MinimumSize.Height + shiftAmount); } // Then put the container panel back on the form, shifted downwards container.Top = shiftAmount; editForm.Controls.Add(container); } finally { editForm.ResumeLayout(); } editForm.FormClosing += OnEditFormClosing; }