Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ArrayList with List<T> in ParentControlDesigner #10289

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,12 @@ private static SnapLine[] GenerateNewToolSnapLines(Rectangle r)
/// <summary>
/// Finds the array of components within the given rectangle. This uses the rectangle to
/// find controls within our control, and then uses those controls to find the actual
/// components. It returns an object array so the output can be directly fed into
/// components. It returns an object list so the output can be directly fed into
/// the selection service.
/// </summary>
internal object[] GetComponentsInRect(Rectangle value, bool screenCoords, bool containRect)
internal List<Control> GetComponentsInRect(Rectangle value, bool screenCoords, bool containRect)
{
ArrayList list = new ArrayList();
List<Control> list = new();
Rectangle rect = screenCoords ? Control.RectangleToClient(value) : value;

IContainer container = Component.Site.Container;
Expand All @@ -878,7 +878,7 @@ internal object[] GetComponentsInRect(Rectangle value, bool screenCoords, bool c
}
}

return list.ToArray();
return list;
}

/// <summary>
Expand Down Expand Up @@ -1255,16 +1255,14 @@ public override void InitializeNewComponent(IDictionary defaultValues)
return;
}

object[] comps = parentDesigner.GetComponentsInRect(bounds, true, true /* component should be fully contained*/);
List<Control> selectedControls = parentDesigner.GetComponentsInRect(bounds, true, true /* component should be fully contained*/);

if (comps is null || comps.Length == 0)
if (selectedControls is null || selectedControls.Count == 0)
{
//no comps to re-parent
return;
}

ArrayList selectedControls = new ArrayList(comps);

//remove this
if (selectedControls.Contains(Control))
{
Expand Down Expand Up @@ -1890,8 +1888,8 @@ protected override void OnMouseDragEnd(bool cancel)
var selSvc = (ISelectionService)GetService(typeof(ISelectionService));
if (selSvc is not null)
{
object[] selection = GetComponentsInRect(offset, true, false /*component does not need to be fully contained*/);
if (selection.Length > 0)
List<Control> selection = GetComponentsInRect(offset, true, false /*component does not need to be fully contained*/);
if (selection.Count > 0)
{
selSvc.SetSelectedComponents(selection);
}
Expand Down Expand Up @@ -2136,7 +2134,7 @@ protected override void PreFilterProperties(IDictionary properties)
/// Control in the toolbox then drags a rectangle around four Buttons on the Form's surface. We'll attempt
/// to re-parent those four Buttons to the newly created Panel.
/// </summary>
private void ReParentControls(Control newParent, ArrayList controls, string transactionName, IDesignerHost host)
private void ReParentControls(Control newParent, List<Control> controls, string transactionName, IDesignerHost host)
{
using DesignerTransaction dt = host.CreateTransaction(transactionName);
var changeService = GetService<IComponentChangeService>();
Expand All @@ -2155,9 +2153,8 @@ private void ReParentControls(Control newParent, ArrayList controls, string tran
changeService?.OnComponentChanging(newParent, controlsProp);

//enumerate the lasso'd controls relocate and re-parent...
foreach (object comp in controls)
foreach (Control control in controls)
{
Control control = comp as Control;
Control oldParent = control.Parent;
Point controlLoc = Point.Empty;

Expand Down
Loading