/// <summary> /// Adds a child control to this control. The control becomes the last control in /// the child control list. If the control is already a child of another control it /// is first removed from that control. /// </summary> public virtual void Add(Control value) { if (value == null) { return; } if (value.GetTopLevel()) { throw new ArgumentException(SR.TopLevelControlAdd); } // Verify that the control being added is on the same thread as // us...or our parent chain. if (Owner.CreateThreadId != value.CreateThreadId) { throw new ArgumentException(SR.AddDifferentThreads); } CheckParentingCycle(Owner, value); if (value._parent == Owner) { value.SendToBack(); return; } // Remove the new control from its old parent (if any) if (value._parent != null) { value._parent.Controls.Remove(value); } // Add the control InnerList.Add(value); if (value._tabIndex == -1) { // Find the next highest tab index int nextTabIndex = 0; for (int c = 0; c < (Count - 1); c++) { int t = this[c].TabIndex; if (nextTabIndex <= t) { nextTabIndex = t + 1; } } value._tabIndex = nextTabIndex; } // if we don't suspend layout, AssignParent will indirectly trigger a layout event // before we're ready (AssignParent will fire a PropertyChangedEvent("Visible"), which calls PerformLayout) #if DEBUG int dbgLayoutCheck = Owner.LayoutSuspendCount; #endif Owner.SuspendLayout(); try { Control oldParent = value._parent; try { // AssignParent calls into user code - this could throw, which // would make us short-circuit the rest of the reparenting logic. // you could end up with a control half reparented. value.AssignParent(Owner); } finally { if (oldParent != value._parent && (Owner._state & STATE_CREATED) != 0) { value.SetParentHandle(Owner.InternalHandle); if (value.Visible) { value.CreateControl(); } } } value.InitLayout(); } finally { Owner.ResumeLayout(false); #if DEBUG Owner.AssertLayoutSuspendCount(dbgLayoutCheck); #endif } // Not putting in the finally block, as it would eat the original // exception thrown from AssignParent if the following throws an exception. LayoutTransaction.DoLayout(Owner, value, PropertyNames.Parent); Owner.OnControlAdded(new ControlEventArgs(value)); }
public static void ExtendFrameIntoClientArea(this Form form, Control glassArea) { if (IsGlassSupported) { if (glassArea.Dock != DockStyle.Top) { glassArea.Dock = DockStyle.Top; glassArea.SendToBack(); } glassArea.BackColor = Color.Transparent; glassArea.Resize += delegate(object sender, EventArgs e) { form.Invalidate(glassArea.Region, true); }; form.Paint += delegate(object sender, PaintEventArgs e) { using (SolidBrush blackBrush = new SolidBrush(Color.Black)) { e.Graphics.FillRectangle(blackBrush, glassArea.ClientRectangle); } }; MARGINS marg; marg.Top = glassArea.Height; marg.Left = 0; marg.Right = 0; marg.Bottom = 0; DwmExtendFrameIntoClientArea(form.Handle, ref marg); glassArea.SetGlassWindowDragable(); } }
/// <summary> /// 抽屉效果。 /// </summary> private void Stretch(ArrayList alPanel, Control myControl, Control myControl1, int MaxValue, int Increment, int Part, int Part1) { stretchFlag = false; for (; myControl.Height - _titleHeight < MaxValue; ) { System.Threading.Thread.Sleep(1); if (myControl1.Height - _titleHeight - Increment <= 0) { myControl1.Height = _titleHeight; } else { myControl1.Height -= Increment; } if (myControl.Height - _titleHeight + Increment >= MaxValue) { myControl.Height = MaxValue + _titleHeight; } else { myControl.Height += Increment; myControl.SendToBack(); } if (Part > Part1) { for (int i = 0; i < alPanel.Count; i++) { if (i > Part1 && i <= Part) { PanelInfo panelInfo = (PanelInfo)alPanel[i]; panelInfo.s_panel.Top -= Increment; } } } else { for (int i = 0; i < alPanel.Count; i++) { if (i > Part && i <= Part1) { PanelInfo panelInfo = (PanelInfo)alPanel[i]; panelInfo.s_panel.Top += Increment; } } } } for (int i = 0; i < alPanel.Count; i++) { if (i > 0) { PanelInfo panelInfo = (PanelInfo)alPanel[i - 1]; PanelInfo panelInfo1 = (PanelInfo)alPanel[i]; panelInfo1.s_panel.Top =panelInfo.s_panel.Top + panelInfo.s_panel.Height + _splitHeight; } } stretchFlag = true; }
// Add a control to this collection. public virtual void Add(Control value) { if(value != null) { if(value.Parent == owner) { // We are already under this owner, so merely // send it to the back of its sibling stack. value.SendToBack(); } else { // Suspend layout on the parent while we do this. owner.SuspendLayout(); try { // Change the parent to the new owner. value.Parent = owner; // Assign the next tab order if the control doesnt have one. if (value.tabIndex == -1) { int lastIndex = 0; for (int i = 0; i < owner.numChildren; i++) { int index = owner.children[i].TabIndex; if (lastIndex <= index) lastIndex = index + 1; } value.tabIndex = lastIndex; } } finally { // Resume layout, but don't perform it yet. owner.ResumeLayout(false); } // Now perform layout on the control if necessary. if (owner.IsHandleCreated && value.Visible) { // Make sure the control exists. value.CreateControl(); owner.PerformLayout(value, "Parent"); } } } }
private void CheckLabelPosition(List<Control> controls, Control control, int bottom, int right) { //if label is in the group box, then add it DragableLabel label = control as DragableLabel; if (label.Top >= this.Top && (label.Top + label.Height) <= bottom && label.Left >= this.Left && (label.Left + label.Width) <= right) { label.BringToFront(); if (label.LabelFor != null) { label.LabelFor.BringToFront(); } } //if the label is not in the group box, then remove it's linked control else { control.SendToBack(); controls.Remove(control); if (label.LabelFor != null && controls.Contains(label.LabelFor)) { label.LabelFor.SendToBack(); controls.Remove(label.LabelFor); controls.Remove(label); } } }