/// <summary> /// Activates the specified control. /// </summary> /// <param name="active">The <see cref="Control"/> to activate.</param> /// <returns>true if the control is successfully activated; otherwise, false.</returns> /// <remarks> /// http://msdn.microsoft.com/en-us/library/bb339151(v=vs.110).aspx /// </remarks> public bool ActivateControl(Control active) { if (Controls.Contains(active)) { active.Select(); ActiveControl = active; return true; } return false; }
/// <summary> /// Sets the index of the specified child control in the collection to the specified index value. /// </summary> /// <param name="child">The child <see cref="Control"/> to search for.</param> /// <param name="newIndex">The new index value of the control.</param> /// <remarks> /// http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.setchildindex(v=vs.110).aspx /// </remarks> public virtual void SetChildIndex(Control child, int newIndex) { lock (_internalSyncRoot) { if (_controls.Contains(child)) { if (newIndex >= Count) { _controls.Remove(child); _controls.Add(child); } else { _controls.Remove(child); _controls.Insert(newIndex, child); } } else { throw new ArgumentException(); } } }
/// <summary> /// Removes the specified control from the control collection. /// </summary> /// <param name="value">The <see cref="Control"/> to remove from the <see cref="ControlCollection"/>.</param> /// <remarks> /// http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.remove(v=vs.110).aspx /// </remarks> public virtual void Remove(Control value) { lock (_internalSyncRoot) { _controls.Remove(value); } }
/// <summary> /// Initializes a new instance of the <see cref="ControlCollection"/> class. /// </summary> /// <param name="owner">A <see cref="Control"/> representing the control that owns the control collection.</param> public ControlCollection(Control owner) { _owner = owner; _controls = new List<Control>(); }
/// <summary> /// Retrieves the index of the specified control in the control collection. /// </summary> /// <param name="control">The <see cref="Control"/> to locate in the collection.</param> /// <returns>A zero-based index value that represents the position of the specified <see cref="Control"/> in the <see cref="ControlCollection"/>.</returns> /// <remarks> /// http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.indexof(v=vs.110).aspx /// </remarks> public int IndexOf(Control control) { lock (_internalSyncRoot) { return _controls.IndexOf(control); } }
/// <summary> /// Retrieves the index of the specified child control within the control collection, and optionally raises an exception if the specified control is not within the control collection. /// </summary> /// <param name="child">The <see cref="Control"/> to search for in the control collection.</param> /// <param name="throwException">true to throw an exception if the <see cref="Control"/> specified in the child parameter is not a control in the <see cref="ControlCollection"/>; otherwise, false.</param> /// <returns></returns> /// <remarks> /// http://msdn.microsoft.com/en-us/library/ta8fcz9s(v=vs.110).aspx /// </remarks> public virtual int GetChildIndex(Control child, bool throwException) { lock (_internalSyncRoot) { if (_controls.Contains(child)) { return _controls.IndexOf(child); } if (throwException) { throw new ArgumentException(); } return -1; } }
/// <summary> /// Retrieves the index of the specified child control within the control collection. /// </summary> /// <param name="child">The <see cref="Control"/> to search for in the control collection.</param> /// <returns>A zero-based index value that represents the location of the specified child control within the control collection.</returns> /// <remarks> /// http://msdn.microsoft.com/en-us/library/1fz293fh(v=vs.110).aspx /// </remarks> public int GetChildIndex(Control child) { lock (_internalSyncRoot) { if (_controls.Contains(child)) { return _controls.IndexOf(child); } throw new KeyNotFoundException(); } }
/// <summary> /// Activates the next control. /// </summary> /// <param name="ctl">The <see cref="Control"/> at which to start the search.</param> /// <param name="forward">true to move forward in the tab order; false to move backward in the tab order.</param> /// <param name="tabStopOnly">true to ignore the controls with the TabStop property set to false; otherwise, false.</param> /// <param name="nested">true to include nested (children of child controls) child controls; otherwise, false.</param> /// <param name="wrap">true to continue searching from the first control in the tab order after the last control has been reached; otherwise, false.</param> /// <returns>true if a control was activated; otherwise, false.</returns> /// <remarks> /// http://msdn.microsoft.com/en-us/library/system.windows.forms.control.selectnextcontrol(v=vs.110).aspx /// </remarks> public bool SelectNextControl(Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) { throw new NotImplementedException(); }
/// <summary> /// Adds an array of control objects to the collection. /// </summary> /// <param name="controls">An array of <see cref="Control"/> objects to add to the collection.</param> /// <remarks> /// http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.addrange(v=vs.110).aspx /// </remarks> public virtual void AddRange(Control[] controls) { lock (_internalSyncRoot) { foreach (Control control in controls) { InternalAdd(control); } } }
private void InternalAdd(Control value) { if (_owner == value) { throw new ArgumentException($"The control {nameof(value)} cannot be the same as the {nameof(Owner)}."); } value.TabIndex = _controls.Count; _controls.Add(value); value.Parent = _owner; }
/// <summary> /// Adds the specified control to the control collection. /// </summary> /// <param name="value">The <see cref="Control"/> to add to the control collection.</param> /// <remarks> /// http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.add(v=vs.110).aspx /// </remarks> public virtual void Add(Control value) { lock (_internalSyncRoot) { InternalAdd(value); } }
/// <summary> /// Initializes a new instance of the <see cref="ControlEventArgs"/> class for the specified control. /// </summary> /// <param name="control">The <see cref="Control"/> to store in this event.</param> /// <remarks> /// http://msdn.microsoft.com/en-us/library/system.windows.forms.controleventargs.controleventargs(v=vs.110).aspx /// </remarks> public ControlEventArgs(Control control) { Control = control; }
/// <summary> /// Initializes a new instance of the Control class as a child control, with specific text. /// </summary> /// <param name="parent">The <see cref="Control"/> to be the parent of the control.</param> /// <param name="text">The text displayed by the control.</param> /// <remarks> /// http://msdn.microsoft.com/en-us/library/wawy06xc(v=vs.110).aspx /// </remarks> public Control(Control parent, string text) : this(text) { Parent = parent; }
/// <summary> /// Retrieves the next control forward or back in the tab order of child controls. /// </summary> /// <param name="ctl">The <see cref="Control"/> to start the search with.</param> /// <param name="forward">true to search forward in the tab order; true to search backward.</param> /// <returns>The next <see cref="Control"/> in the tab order.</returns> /// <remarks> /// http://msdn.microsoft.com/en-us/library/system.windows.forms.control.getnextcontrol(v=vs.110).aspx /// </remarks> public Control GetNextControl(Control ctl, bool forward) { throw new NotImplementedException(); }
private ControlCollection(Control owner, List<Control> controls) : this(owner) { _controls = controls; }
/// <summary> /// Determines whether the specified control is a member of the collection. /// </summary> /// <param name="control">The <see cref="Control"/> to locate in the collection.</param> /// <returns>true if the <see cref="Control"/> is a member of the collection; otherwise, false.</returns> public bool Contains(Control control) { lock (_internalSyncRoot) { return _controls.Contains(control); } }
/// <summary> /// Initializes a new instance of the Control class as a child control, with specific text, size, and location. /// </summary> /// <param name="parent">The <see cref="Control"/> to be the parent of the control.</param> /// <param name="text">The text displayed by the control.</param> /// <param name="left">The X position of the control, in pixels, from the left edge of the control's container. The value is assigned to the <see cref="Left"/> property.</param> /// <param name="top">The Y position of the control, in pixels, from the top edge of the control's container. The value is assigned to the <see cref="Top"/> property.</param> /// <param name="width">The width of the control, in pixels. The value is assigned to the <see cref="Width"/> property.</param> /// <param name="height">The height of the control, in pixels. The value is assigned to the <see cref="Height"/> property.</param> /// <remarks> /// http://msdn.microsoft.com/en-us/library/x59hwbb3(v=vs.110).aspx /// </remarks> public Control(Control parent, string text, int left, int top, int width, int height) : this(text, left, top, width, height) { Parent = parent; }