gFinger 손끝으로 만드는 세상


Tray로 Form을 Icon화 하기



Form애  notifyIcon1 추가

private void Form1_Load(object sender, EventArgs e)
        {
            ContextMenu ctx = new ContextMenu();
            ctx.MenuItems.Add(new MenuItem("Open",
                new EventHandler((s, ex) => AppearingMainForm())));
            ctx.MenuItems.Add("-");
            ctx.MenuItems.Add(new MenuItem("Exit", new EventHandler((s, ex) => this.Close())));
            notifyIcon1.ContextMenu = ctx;

}

       private void Form1_MinimumSizeChanged(object sender, EventArgs e)
        {
            ShownNotifyIcon();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            AppearingMainForm();
        }

  private void ShownNotifyIcon()
        {
            WindowState = FormWindowState.Minimized;
            notifyIcon1.Visible = true;
        //    notifyIcon1.Icon = SystemIcons.Application;
        }

        private void AppearingMainForm()
        {
            notifyIcon1.Visible = false;
            this.Show();
            this.WindowState = FormWindowState.Normal;
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            if (FormWindowState.Minimized == this.WindowState)
            {
                ShownNotifyIcon();
            }
            else if (FormWindowState.Normal == this.WindowState)
            {
                AppearingMainForm();
            }
        }

        private void notifyIcon1_MouseDoubleClick_1(object sender, MouseEventArgs e)
        {
            // 아이콘을 더블클릭하면 폼 화면을 보여줌
            AppearingMainForm();
        }


 


'컴퓨터 이야기 > c#' 카테고리의 다른 글

Text File Save Dialog  (0) 2018.06.09
File Name을 선택해서 Text 파일 읽기  (0) 2018.06.09
How to move and resize a form without a border?  (0) 2018.06.09
Form을 Drag해서 이동  (0) 2018.06.09
Program 2번 실행 방지  (0) 2018.06.06