dotnet / dotnet/winforms

ToolStripSeparator.GetPreferredSize has a suspicious always-true if check

Open
#2,576 5 comments 0 reactions 0 assignees View on GitHub
:beetle: bug area-controls-StripControls area-Layout
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

The implementation of `ToolStripSeparator.GetPreferredSize` is as follows:

```cs
public override Size GetPreferredSize(Size constrainingSize)
{
ToolStrip parent = ParentInternal;

if (parent == null)
{
parent = Owner;
}
if (parent == null)
{
return new Size(ToolStrip_SEPARATORTHICKNESS, ToolStrip_SEPARATORTHICKNESS);
}

if (parent is ToolStripDropDownMenu dropDownMenu)
{
return new Size(parent.Width - (parent.Padding.Horizontal - dropDownMenu.ImageMargin.Width), ToolStrip_SEPARATORTHICKNESS);
}
else
{
if (parent.LayoutStyle != ToolStripLayoutStyle.HorizontalStackWithOverflow || parent.LayoutStyle != ToolStripLayoutStyle.VerticalStackWithOverflow)
{
// we dont actually know what size to make it, so just keep it a stock size.
constrainingSize.Width = ToolStrip_SEPARATORHEIGHT;
constrainingSize.Height = ToolStrip_SEPARATORHEIGHT;
}
if (IsVertical)
{
return new Size(ToolStrip_SEPARATORTHICKNESS, constrainingSize.Height);
}
else
{
return new Size(constrainingSize.Width, ToolStrip_SEPARATORTHICKNESS);
}
}

}
```

Notice this case: `if (parent.LayoutStyle != ToolStripLayoutStyle.HorizontalStackWithOverflow || parent.LayoutStyle != ToolStripLayoutStyle.VerticalStackWithOverflow)`

This appears to always be true, as `parent.LayoutStyle` can't be both `HorizontalStackWithOverflow` and `VerticalStackWithOverflow`.

Should this actually be an `&&` check rather than `||`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.