在 .NET 中创建新的最大化 MDI 子窗体时出现图标问题

发布于 2024-07-22 14:44:27 字数 313 浏览 6 评论 0原文

我有一个 .NET 3.5 MDI WinForms 应用程序。

我设置了子表单的 Icon 属性,并且图标正确显示在表单的左上角。 然后我最大化子窗体,图标仍然可以。

在子窗体仍然最大化的情况下,我打开另一个子窗口,它会自动最大化。 此窗体的图标不是 Icon 属性中的图标,而是默认的 .NET 图标(带有蓝色、红色和黄色方块的图标)。 但是,如果我调整 MDI 父窗体的大小,图标会自行重置并正确显示。

有谁有解决方法或知道为什么会发生这种情况?

I have a .NET 3.5 MDI WinForms application.

I set a a child form's Icon property, and the icon shows up correctly in the top left corner of the form. I then maximize the child form and the icon is still OK.

With the child form still maximized, I open another child window, which automatically comes up maximized. This form's icon is not the one in the Icon property, but the default .NET icon (the one with the blue, red, and yellow squares). However, if I resize the MDI parent form, the icon resets itself and displays properly.

Does anyone have a workaround or know why this happens?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

拥抱没勇气 2024-07-29 14:44:27

对 Calanus 解决方案的轻微修改:

    private void MdiBase_Load(object sender, EventArgs e)
    {
        // Fixes bug where loading form maximised in MDI window shows incorrect icon.
        this.Icon = Icon.Clone() as Icon;
    }

这允许您在设计时设置图标(就像对其他表单一样),并且不需要任何硬编码文件或资源访问。

A slight modification to Calanus' solution:

    private void MdiBase_Load(object sender, EventArgs e)
    {
        // Fixes bug where loading form maximised in MDI window shows incorrect icon.
        this.Icon = Icon.Clone() as Icon;
    }

This allows you to set the icon at design time (just as you would for other forms), and does not need any hard-coded file or resource accessing.

笙痞 2024-07-29 14:44:27

是的,我找到了解决方案...

解决方法是在子窗体的加载事件上再次设置图标,如下所示:

private void StatsForm_Load(object sender, EventArgs e)
{
    //bug that means you have to set the desired icon again otherwise it reverts to default when child form is maximised
    Icon = new System.Drawing.Icon("research.ico");
}

这确实意味着您必须首先将有问题的图标文件添加到您的 VS 项目/解决方案并将其设置为“始终复制”,以便在构建解决方案时复制该解决方案。

华泰
哲水蚤属

Right I have found a solution...

The workaround for this is to set the icon again on the load event of the child form as follows:

private void StatsForm_Load(object sender, EventArgs e)
{
    //bug that means you have to set the desired icon again otherwise it reverts to default when child form is maximised
    Icon = new System.Drawing.Icon("research.ico");
}

This does mean that you will have to first add the icon file in question into your VS project/solution and set it to "Copy Always" so that is copied when your solution is built.

HTH
Calanus

糖果控 2024-07-29 14:44:27

我发现唯一的解决方案是停用然后重新激活 MDI 子项:

document.Show();
// Work-around for error in WinForms that causes MDI children to be loaded with the default .NET icon when opened maximised.
ActivateMdiChild(null);
ActivateMdiChild(document);

这是 MSDN 论坛上的回复 对我有用。

I found that the only solution was to deactivate and then reactivate the MDI child:

document.Show();
// Work-around for error in WinForms that causes MDI children to be loaded with the default .NET icon when opened maximised.
ActivateMdiChild(null);
ActivateMdiChild(document);

This is the solution given in this reply on MSDN forums and it worked for me.

硬不硬你别怂 2024-07-29 14:44:27
private void frmChild_Shown(object sender, EventArgs e)
{
    // Work-around for maximized BUG
    this.Icon = this.MdiParent.Icon;
    this.WindowState = FormWindowState.Normal;
    this.WindowState = FormWindowState.Maximized;
}
private void frmChild_Shown(object sender, EventArgs e)
{
    // Work-around for maximized BUG
    this.Icon = this.MdiParent.Icon;
    this.WindowState = FormWindowState.Normal;
    this.WindowState = FormWindowState.Maximized;
}
爱,才寂寞 2024-07-29 14:44:27

我发现这也可以解决问题。

myForm.WindowState = FormWindowState.Normal;
myForm.Show();
myForm.WindowState = FormWindowState.Maximized;

I found out this will fix the problem as well.

myForm.WindowState = FormWindowState.Normal;
myForm.Show();
myForm.WindowState = FormWindowState.Maximized;
怎樣才叫好 2024-07-29 14:44:27

将其添加为 MDI 子项的 Form_Load 方法中的第一行对我有用:

this.Icon = new Icon(this.Icon, this.Icon.Size);

Adding this as the first line in the Form_Load method on the MDI Children works for me:

this.Icon = new Icon(this.Icon, this.Icon.Size);
溺渁∝ 2024-07-29 14:44:27

我的解决方案:
将 MdiChild“ShowIcon”属性设置为 true,指定一个 1x1 透明图标。 问题解决了。

My solution:
Leave the MdiChild "ShowIcon" property set to true, assign a 1x1 transparent icon. Problem solved.

花想c 2024-07-29 14:44:27
form.WindowState = FormWindowState.Normal
form.Show()
form.WindowState = FormWindowState.Maximized
form.Show()

解决了我的问题!

form.WindowState = FormWindowState.Normal
form.Show()
form.WindowState = FormWindowState.Maximized
form.Show()

Solved my problem!

白馒头 2024-07-29 14:44:27

我发现解决此问题的最佳解决方法是

aNewForm.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
AddHandler aNewForm.SizeChanged, AddressOf Form_SizeChanged

aNewForm.Show()
aNewForm.WindowState = FormWindowState.Maximized

RemoveHandler aNewForm.SizeChanged, AddressOf Form_SizeChanged

处理程序

Protected Sub Form_SizeChanged(ByVal sender As Object, ByVal e As EventArgs)

    If WindowState = FormWindowState.Maximized Then
        If FormBorderStyle <> FormBorderStyle.Sizable Then FormBorderStyle = FormBorderStyle.Sizable
    End If

End Sub

The best workaround that I found to fix this issue is here.

aNewForm.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
AddHandler aNewForm.SizeChanged, AddressOf Form_SizeChanged

aNewForm.Show()
aNewForm.WindowState = FormWindowState.Maximized

RemoveHandler aNewForm.SizeChanged, AddressOf Form_SizeChanged

the handler

Protected Sub Form_SizeChanged(ByVal sender As Object, ByVal e As EventArgs)

    If WindowState = FormWindowState.Maximized Then
        If FormBorderStyle <> FormBorderStyle.Sizable Then FormBorderStyle = FormBorderStyle.Sizable
    End If

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文