본문 바로가기

Development/WPF

[WPF] NotifyTrayIcon

반응형
환경 : Visual Studio 2015

tray Icon

	private void SetNotifyTrayIcon()
        {
            try
            {
                System.Windows.Forms.ContextMenu menu = new System.Windows.Forms.ContextMenu();
                // 아이콘 설정부분
                notify = new System.Windows.Forms.NotifyIcon();
                notify.Icon = new System.Drawing.Icon(@"icon.ico");  // 외부아이콘 사용 시


                //notify.Icon = Properties.Resources.icon;   // Resources 아이콘 사용 시
                notify.Visible = true;
                notify.ContextMenu = menu;
                notify.Text = "Test";

                // 아이콘 더블클릭 이벤트 설정
                notify.DoubleClick += Notify_DoubleClick;

                System.Windows.Forms.MenuItem item1 = new System.Windows.Forms.MenuItem();
                menu.MenuItems.Add(item1);
                item1.Index = 0;
                item1.Text = "프로그램 종료";
                item1.Click += delegate (object click, EventArgs eClick)
                {
                    System.Windows.Application.Current.Shutdown();
                    notify.Dispose();
                };

                System.Windows.Forms.MenuItem item2 = new System.Windows.Forms.MenuItem();
                menu.MenuItems.Add(item2);
                item2.Index = 0;
                item2.Text = "프로그램 설정";
                item2.Click += delegate (object click, EventArgs eClick)
                {
                    Settings();
                };

                //this.Close();   // 시작시 창 닫음 (아이콘만 띄우기 위함)
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SetNotifyTrayIcon()");
            }
        }

참조한 사이트가 있는데 정확히 기억이 나지 않는다. 

일단 위의 Method로 기본적인 TrayaIcon은 해결...

반응형