在.NET中創建新的最大化MDI子窗體的圖標問題

[英]Problem with icon on creating new maximized MDI child form in .NET


I have a .NET 3.5 MDI WinForms application.

我有一個.NET 3.5 MDI WinForms應用程序。

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.

我設置了一個子窗體的Icon屬性,該圖標在窗體的左上角正確顯示。然后我最大化子表單,圖標仍然可以。

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.

隨着子窗體仍然最大化,我打開另一個子窗口,自動出現最大化。此表單的圖標不是Icon屬性中的圖標,而是默認的.NET圖標(帶有藍色,紅色和黃色方塊的圖標)。但是,如果我調整MDI父窗體的大小,圖標將自行重置並正確顯示。

Does anyone have a workaround or know why this happens?

有沒有人有解決方法或知道為什么會這樣?

9 个解决方案

#1


9  

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:

解決方法是在子窗體的load事件上再次設置圖標,如下所示:

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.

這意味着您必須首先將有問題的圖標文件添加到VS項目/解決方案中,並將其設置為“始終復制”,以便在構建解決方案時復制該文件。

HTH Calanus

#2


11  

A slight modification to Calanus' solution:

對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;
    }

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.

這允許您在設計時設置圖標(就像您對其他表單一樣),並且不需要任何硬編碼文件或資源訪問。

#3


4  

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

我發現唯一的解決方案是停用然后重新激活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);

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

這是在MSDN論壇上的回復中給出的解決方案,它對我有用。

#4


3  

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;
}

#5


2  

I found out this will fix the problem as well.

我發現這也將解決問題。

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

#6


1  

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

Solved my problem!

解決了我的問題!

#7


0  

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

我的解決方案:將MdiChild“ShowIcon”屬性設置為true,指定1x1透明圖標。問題解決了。

#8


0  

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

#9


0  

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

將此作為MDI Children中Form_Load方法的第一行添加為我工作:

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/05/20/7210e13d95840e2d1b4be34ccebbb252.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com