我有一个 .NET 3.5 MDI WinForms 应用程序。
我设置了一个子表单的Icon
属性,图标正确显示在表单的左上角。然后我最大化子窗体,图标仍然可以。
在子窗体仍然最大化的情况下,我打开另一个子窗口,它会自动最大化。此表单的图标不是Icon
属性中的图标,而是默认的 .NET 图标(带有蓝色、红色和黄色方块的那个)。但是,如果我调整MDI 父窗体的大小,图标会自行重置并正确显示。
有没有人有解决方法或知道为什么会这样?
对 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;
}
这允许您在设计时设置图标(就像其他表单一样),并且不需要任何硬编码文件或资源访问。
是的,我找到了解决方案...
解决方法是在子窗体的加载事件上再次设置图标,如下所示:
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 项目/解决方案中,并将其设置为“始终复制”,以便在构建解决方案时进行复制。
HTH 卡兰努斯
我发现唯一的解决方案是停用然后重新激活 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 论坛上的回复中给出的解决方案,它对我有用。
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;
}
我发现这也可以解决问题。
myForm.WindowState = FormWindowState.Normal;
myForm.Show();
myForm.WindowState = FormWindowState.Maximized;
我的解决方案:将 MdiChild“ShowIcon”属性设置为 true,分配一个 1x1 透明图标。问题解决了。
将此添加为 MDI Children 的 Form_Load 方法的第一行对我有用:
this.Icon = new Icon(this.Icon, this.Icon.Size);
form.WindowState = FormWindowState.Normal
form.Show()
form.WindowState = FormWindowState.Maximized
form.Show()
解决了我的问题!
我发现解决此问题的最佳解决方法是在这里。
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