Microsoft KB Archive/836673

= 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 =

Article ID: 836673

Article Last Modified on 8/28/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * 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 description for Form1. ///    public class Form1 : System.Windows.Forms.Form {       ///         /// Required designer variable. ///        private System.ComponentModel.Container components = null; public Form1 {           //            // Required for Windows Form Designer support //           InitializeComponent;

//           // TODO: Add any constructor code after InitializeComponent call //       }        ///         /// Clean up any resources being used. ///        protected override void Dispose( bool disposing ) {           if( disposing ) {               if (components != null) {                   components.Dispose; }           }            base.Dispose( disposing ); }       #region Windows Form Designer generated code ///        /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///        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(&quot;$this.Icon&quot;))); this.Name = &quot;Form1&quot;; this.ShowInTaskbar = false; this.Text = &quot;Form1&quot;; this.Load += new System.EventHandler(this.Form1_Load); }       #endregion

///        /// The main entry point for the application. ///        [STAThread]

static void Main {           Application.Run(new Form1); }       [DllImport(&quot;user32.dll&quot;)] private static extern int SendMessage(IntPtr hwnd, int message, int wParam, IntPtr lParam); [DllImport(&quot;user32.dll&quot;, 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 &quot;Applies to&quot; section.



Steps to reproduce the behavior
 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project.

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

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

The Properties window appears.</li> 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.</li> 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

</li> In the Properties window, click the ShowInTaskBar property, and then set the value to False.</li> On the Debug menu, click Start to run the application.</li> 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.</li></ol>

Keywords: kbbug kbuser kbproperties kbappdev kbdisplay kbcontrol kbvs2002sp1sweep KB836673

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.