Skip to content
Open
Show file tree
Hide file tree
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 @@ -801,7 +801,21 @@ protected virtual void OnUnsubscribeControlEvents(Control? control)
/// </remarks>
private void SyncControlParent()
{
ReadOnlyControlCollection? newControls = GetControlCollection(ParentInternal);
ToolStrip? parent = ParentInternal;

if (parent is null || _control is null)
{
return;
}

if (_control.IsHandleCreated && !parent.IsHandleCreated)
{
// The hosted control already has a native handle (for example, when moving to the
// overflow dropdown). Ensure the ToolStrip parent has a handle before reparenting.
parent.CreateControl(ignoreVisible: true);
}

ReadOnlyControlCollection? newControls = GetControlCollection(parent);
newControls?.AddInternal(_control);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,40 @@ public void ToolStripControlHost_AccessibleName_SetDisposed_ThrowsObjectDisposed
Assert.Throws<ObjectDisposedException>(() => item.AccessibleName = "value");
}

[WinFormsFact]
public void ToolStripControlHost_ReparentToOverflowWithCreatedControl()
{
using Form form = new();
using ToolStrip toolStrip = new()
{
Dock = DockStyle.None,
CanOverflow = true
};
using ToolStripComboBox comboBox = new();
using ToolStripProgressBar progressBar = new();

toolStrip.Items.AddRange([comboBox, progressBar]);
form.Controls.Add(toolStrip);

form.Show();

Assert.True(toolStrip.IsHandleCreated);
_ = comboBox.Control.Handle;
_ = progressBar.Control.Handle;
Assert.True(comboBox.Control.IsHandleCreated);
Assert.True(progressBar.Control.IsHandleCreated);

toolStrip.AutoSize = false;
toolStrip.Width = 10;
toolStrip.PerformLayout();

Assert.True(toolStrip.OverflowButton.Visible);

toolStrip.OverflowButton.DropDown.CreateControl(ignoreVisible: true);

Assert.True(toolStrip.OverflowButton.DropDown.IsHandleCreated);
}

[WinFormsTheory]
[EnumData<AccessibleRole>]
public void ToolStripControlHost_AccessibleRole_Set_GetReturnsExpected(AccessibleRole value)
Expand Down