BUG: The icon that represents your form appears as a blank form icon in Visual C# .NET if you set the ShowInTaskBar property to False (836673)
The information in this article applies to:
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
SYMPTOMSYou set the ShowInTaskBar property of a Microsoft Windows form to False. When you press the ALT+TAB key combination to move the control
focus from the form to any other program, the icon that represents your form
appears as a blank form icon.WORKAROUNDTo make sure that the correct icon appears when you press
the ALT+TAB key combination to move the control focus from the form to any
other program while the ShowInTaskbar property is set to False, use the following code. using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.ShowInTaskbar = false;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int message, int wParam, IntPtr lParam);
[DllImport("user32.dll", ExactSpelling=true)]
private static extern IntPtr GetWindow(IntPtr hwnd, int cmd);
private IntPtr GetTopLevelOwner(Control c)
{
IntPtr hwndOwner = c.Handle;
IntPtr hwndCurrent = c.Handle;
while (hwndCurrent != (IntPtr)0)
{
hwndCurrent = GetWindow(hwndCurrent, GW_OWNER);
if (hwndCurrent != (IntPtr)0) { hwndOwner = hwndCurrent; }
}
return hwndOwner;
}
private const int WM_SETICON = 0x80;
private const int GW_OWNER = 4;
private const int ICON_SMALL = 0;
private const int ICON_BIG = 1;
private void Form1_Load(object sender, System.EventArgs e)
{
SendMessage(GetTopLevelOwner(this), WM_SETICON, ICON_BIG, this.Icon.Handle);
}
private void Form1_Closed(object sender, System.EventArgs e)
{
SendMessage(GetTopLevelOwner(this), WM_SETICON, ICON_BIG, new IntPtr(0));
}
}
} STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed in the "Applies to"
section.
Modification Type: | Minor | Last Reviewed: | 8/28/2005 |
---|
Keywords: | kbvs2002sp1sweep kbUser kbProperties kbdisplay kbAppDev kbControl kbbug KB836673 kbAudDeveloper kbAudEndUser |
---|
|