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

SYMPTOMS

You 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.

WORKAROUND

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

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.

    The New Project dialog box appears.
  3. Under Project Types, click Visual C# Projects.
  4. Under Templates, click Windows Application.
  5. Type WindowsApplication1 in the Name box, and then click OK.

    By default, the Form1.cs file appears.
  6. In Design view, right-click the Form1 form, and then click Properties.

    The Properties window appears.
  7. In the Properties window, click the Icon property, and then click the ellipsis button (...) that is located next to the Icon property value.

    The Open dialog box appears.
  8. In the folder that contains the icon (.ico) files, click an .ico file, and then click Open.

    Note By default, the .ico files are installed in a subfolder of the following folder:

    C:\Program Files\Microsoft Visual Studio .NET\Common7\Graphics\icons

  9. In the Properties window, click the ShowInTaskBar property, and then set the value to False.
  10. On the Debug menu, click Start to run the application.
  11. Press the ALT+TAB key combination to determine what programs are currently running on your computer.

    The icon that represents your form appears as a blank form icon instead of as the icon that you selected.

Modification Type:MinorLast Reviewed:8/28/2005
Keywords:kbvs2002sp1sweep kbUser kbProperties kbdisplay kbAppDev kbControl kbbug KB836673 kbAudDeveloper kbAudEndUser