1. 程式人生 > >最小化程式到右下角

最小化程式到右下角

     首先在主頁面新增notifyIcon控制元件,並且在notifyIcon控制元件的Icon屬性新增.ico圖示。在沒有新增Icon的情況下貌似看不到最小化,但可以在 "Windows任務管理"(Ctrl+Alt+DEL) 的  "程序 "裡可以檢視的到。

         //最小化程式 notifyIcon控制元件的事件
        private void notifyIcon1_MouseDoubleClick(object sender,MouseEventArgs e)
        {
            if (this.WindowState ==FormWindowState

.Maximized)
            {
                this.WindowState = FormWindowState.Minimized;
                this.Hide();
            }
            else
            {
                this.Visible = true;
                this.WindowState = FormWindowState.Maximized;
            }
        }


        //在主頁面程式


        private void Form1_SizeChanged(objectsender, EventArgs e)
        {
            if (this.WindowState ==FormWindowState.Minimized)
            {
                this.Hide();
            }
        }