Skip to content
Merged
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
10 changes: 3 additions & 7 deletions src/System.Windows.Forms/src/System/Windows/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ public bool ShowIcon
set
{
formStateEx[FormStateExShowIcon] = value ? 1 : 0;
if (value)
if (!value)
{
UpdateStyles();
}
Expand Down Expand Up @@ -4250,7 +4250,7 @@ protected override void OnResize(EventArgs e)
/// </summary>
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
protected virtual void OnDpiChanged(DpiChangedEventArgs e)
{
if (e.DeviceDpiNew != e.DeviceDpiOld)
Expand Down Expand Up @@ -5867,11 +5867,7 @@ private unsafe void UpdateWindowIcon(bool redrawFrame)

if (redrawFrame)
{
User32.RedrawWindow(
new HandleRef(this, Handle),
null,
IntPtr.Zero,
User32.RDW.INVALIDATE | User32.RDW.FRAME);
User32.RedrawWindow(new HandleRef(this, Handle), null, IntPtr.Zero, User32.RDW.INVALIDATE | User32.RDW.FRAME);
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public MainForm()
flowLayoutPanelUITypeEditors.PerformLayout();
}

private void toggleIconButton_Click(object sender, EventArgs e)
{
this.ShowIcon = !this.ShowIcon;
}

private void button1_Click(object sender, EventArgs e)
{
new Buttons().Show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
using Moq;
using Xunit;
using WinForms.Common.Tests;
using static Interop;

namespace System.Windows.Forms.Tests
{
public class FormTests : IClassFixture<ThreadExceptionFixture>
{
[Fact]
[WinFormsFact]
public void Form_Ctor_Default()
{
var form = new Form();
using var form = new Form();
Assert.False(form.Active);
Assert.Null(form.ActiveMdiChild);
Assert.False(form.AllowTransparency);
Expand All @@ -31,10 +32,27 @@ public void Form_Ctor_Default()
Assert.False(form.Visible);
}

[Fact]
[WinFormsFact]
public static void Form_Ctor_show_icon_by_default()
{
using var form = new Form();
Assert.True(form.Handle != IntPtr.Zero);

IntPtr hSmallIcon = User32.SendMessageW(form, User32.WM.GETICON, (IntPtr)User32.ICON.SMALL, IntPtr.Zero);
Assert.True(hSmallIcon != IntPtr.Zero);

IntPtr hLargeIcon = User32.SendMessageW(form, User32.WM.GETICON, (IntPtr)User32.ICON.BIG, IntPtr.Zero);
Assert.True(hLargeIcon != IntPtr.Zero);

// normal form doesn't have WS_EX.DLGMODALFRAME set, and show icon
User32.WS_EX extendedStyle = unchecked((User32.WS_EX)(long)User32.GetWindowLong(form, User32.GWL.EXSTYLE));
Assert.False(extendedStyle.HasFlag(User32.WS_EX.DLGMODALFRAME));
}

[WinFormsFact]
public void Form_AcceptButtonGetSet()
{
var form = new Form();
using var form = new Form();
var mock = new Mock<IButtonControl>(MockBehavior.Strict);
mock.Setup(x => x.NotifyDefault(It.IsAny<bool>()));

Expand All @@ -43,11 +61,11 @@ public void Form_AcceptButtonGetSet()
Assert.Equal(mock.Object, form.AcceptButton);
}

[Theory]
[WinFormsTheory]
[CommonMemberData(nameof(CommonTestHelper.GetBoolTheoryData))]
public void Form_Active_Set_GetReturnsExpected(bool value)
{
var form = new Form
using var form = new Form
{
Active = value
};
Expand All @@ -72,23 +90,23 @@ public void Form_ActiveFormNotSetActive()
Assert.False(Form.ActiveForm.Active);
}*/

[Fact]
[WinFormsFact]
public void Form_ActiveMdiChildInternalGetSet()
{
var form = new Form();
var child = new Form();
using var form = new Form();
using var child = new Form();

form.ActiveMdiChildInternal = child;

Assert.NotNull(form.ActiveMdiChildInternal);
Assert.Equal(child, form.ActiveMdiChildInternal);
}

[Fact]
[WinFormsFact]
public void Form_ActiveMdiChildGetSet()
{
var form = new Form();
var child = new Form
using var form = new Form();
using var child = new Form
{
Visible = true,
Enabled = true
Expand All @@ -100,11 +118,11 @@ public void Form_ActiveMdiChildGetSet()
Assert.Equal(child, form.ActiveMdiChild);
}

[Fact]
[WinFormsFact]
public void Form_ActiveMdiChildGetSetChildNotVisible()
{
var form = new Form();
var child = new Form
using var form = new Form();
using var child = new Form
{
Visible = false,
Enabled = true
Expand All @@ -115,11 +133,11 @@ public void Form_ActiveMdiChildGetSetChildNotVisible()
Assert.Null(form.ActiveMdiChild);
}

[Fact]
[WinFormsFact]
public void Form_ActiveMdiChildGetSetChildNotEnabled()
{
var form = new Form();
var child = new Form
using var form = new Form();
using var child = new Form
{
Visible = true,
Enabled = false
Expand Down Expand Up @@ -798,6 +816,38 @@ public void Form_Parent_SetWithNonNullOldParent_GetReturnsExpected(Control value
Assert.False(control.IsHandleCreated);
}

[WinFormsTheory]
[InlineData(false, true)]
[InlineData(true, false)]
public static void ShowIcon_renders_icon_correctly(bool showIcon, bool expectedIconNull)
{
using var form = new Form();
Assert.True(form.Handle != IntPtr.Zero);

form.ShowIcon = showIcon;

IntPtr hSmallIcon = User32.SendMessageW(form, User32.WM.GETICON, (IntPtr)User32.ICON.SMALL, IntPtr.Zero);
IntPtr hLargeIcon = User32.SendMessageW(form, User32.WM.GETICON, (IntPtr)User32.ICON.BIG, IntPtr.Zero);
Assert.Equal(expectedIconNull, hSmallIcon == IntPtr.Zero);
Assert.Equal(expectedIconNull, hLargeIcon == IntPtr.Zero);
}

[WinFormsFact]
public static void ShowIcon_false_should_render_no_icon()
{
using var form = new Form();
Assert.True(form.Handle != IntPtr.Zero);

User32.WS_EX extendedStyle = unchecked((User32.WS_EX)(long)User32.GetWindowLong(form, User32.GWL.EXSTYLE));
Assert.False(extendedStyle.HasFlag(User32.WS_EX.DLGMODALFRAME));

form.ShowIcon = false;

// hiding icon sets WS_EX.DLGMODALFRAME
extendedStyle = unchecked((User32.WS_EX)(long)User32.GetWindowLong(form, User32.GWL.EXSTYLE));
Assert.True(extendedStyle.HasFlag(User32.WS_EX.DLGMODALFRAME));
}

public static IEnumerable<object[]> Parent_SetMdiChild_TestData()
{
yield return new object[] { null };
Expand Down