欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

winform如何让窗体不显示Icon但在任务栏中显示Icon

程序员文章站 2022-05-25 21:16:58
...
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            const int WM_SETICON = 0x80;
            Bitmap smallIcon = new Bitmap(SystemInformation.SmallIconSize.Width, SystemInformation.SmallIconSize.Height);
            SendMessage(this.Handle, WM_SETICON, (IntPtr)0, smallIcon.GetHicon());
            SendMessage(this.Handle, WM_SETICON, (IntPtr)1, this.Icon.Handle);
        }

        [DllImport("user32.dll")]
        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);