c# 포인트 앤 클릭 최소화 시 트레이 백그라운드로 최소화

4346 단어
문장을 정리하였다.
1. WinForm 창 속성 설정showinTask=false
2. notifyicon 컨트롤 notify Icon1을 추가하고 컨트롤 notify Icon1의 속성 Icon에 icon 아이콘을 추가합니다. 
3. 창 최소화 이벤트 추가하기 (우선 이벤트 인용을 추가해야 함):
코드는 다음과 같습니다.
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged); 
//        InitializeComponent()           
private void Form1_SizeChanged(object sender, EventArgs e) 
{ 
    if(this.WindowState == FormWindowState.Minimized) 
    { 
        this.Hide(); 
        this.notifyIcon1.Visible=true; 
    } 
}

4. 클릭 아이콘 이벤트 추가(먼저 이벤트 참조를 추가해야 함):
        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.WindowState = FormWindowState.Normal;
            this.notifyIcon1.Visible = false;
        } 

5. 마우스 오른쪽 버튼 메뉴를 notify Icon에 추가할 수 있습니다.
메인 창에 ContextMenu 컨트롤 NicontextMenu를 끌어다 놓고, 누르면 위아래 메뉴에 메뉴를 추가합니다. notifyIcon1의 ContextMenu 동작에서 NicontextMenu를 위아래 메뉴로 선택하십시오. 
코드는 다음과 같습니다.
    this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(    this.components); 
    this.NicontextMenu = new System.Windows.Forms.ContextMenu(); 
    this.menuItem_Hide = new System.Windows.Forms.MenuItem(); 
    this.menuItem_Show = new System.Windows.Forms.MenuItem(); 
    this.menuItem_Aubot = new System.Windows.Forms.MenuItem(); 
    this.menuItem_Exit = new System.Windows.Forms.MenuItem(); 
    this.notifyIcon1.ContextMenu =     this.NicontextMenu; 
    this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject( "NotifyIcon.Icon "))); 
    this.notifyIcon1.Text = " "; 
    this.notifyIcon1.Visible = true; 
    this.notifyIcon1.DoubleClick += new System.EventHandler(    this.notifyIcon1_DoubleClick); 
    this.notifyIcon1.Click += new System.EventHandler(    this.notifyIcon1_Click); 
    this.NicontextMenu.MenuItems.AddRange( 
new System.Windows.Forms.MenuItem[] 
{ 
    this.menuItem_Hide, 
    this.menuItem_Show, 
    this.menuItem_Aubot, 
    this.menuItem_Exit 
} 
); 
// 
// menuItem_Hide 
// 
    this.menuItem_Hide.Index = 0; 
    this.menuItem_Hide.Text = "   "; 
    this.menuItem_Hide.Click += new System.EventHandler(    this.menuItem_Hide_Click); 
// 
// menuItem_Show 
// 
    this.menuItem_Show.Index = 1; 
    this.menuItem_Show.Text = "   "; 
    this.menuItem_Show.Click += new System.EventHandler(    this.menuItem_Show_Click); 
// 
// menuItem_Aubot 
// 
    this.menuItem_Aubot.Index = 2; 
    this.menuItem_Aubot.Text = "   "; 
    this.menuItem_Aubot.Click += new System.EventHandler(    this.menuItem_Aubot_Click); 
// 
// menuItem_Exit 
// 
    this.menuItem_Exit.Index = 3; 
    this.menuItem_Exit.Text = "   "; 
    this.menuItem_Exit.Click += new System.EventHandler(    this.menuItem_Exit_Click); 
protected override void OnClosing(CancelEventArgs e) 
{ 
    this.ShowInTaskbar = false; 
    this.WindowState = FormWindowState.Minimized; 
e.Cancel = true; 
} 
protected override void OnClosing(CancelEventArgs e) 
{ 
//    this.ShowInTaskbar = false; 
    this.WindowState = FormWindowState.Minimized; 
e.Cancel = true; 
} 
private void CloseCtiServer() 
{ 
timer.Enabled = false; 
DJ160API.DisableCard(); 
    this.NotifyIcon.Visible = false; 
    this.Close(); 
    this.Dispose(); 
Application.Exit(); 
} 
private void HideCtiServer() 
{ 
    this.Hide(); 
} 
private void ShowCtiServer() 
{ 
    this.Show(); 
    this.WindowState = FormWindowState.Normal; 
    this.Activate(); 
} 
private void CtiManiForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) 
{ 
    this.CloseCtiServer(); 
} 
private void menuItem_Show_Click(object sender, System.EventArgs e) 
{ 
    this.ShowCtiServer(); 
} 
private void menuItem_Aubot_Click(object sender, System.EventArgs e) 
{ 
} 
private void menuItem_Exit_Click(object sender, System.EventArgs e) 
{ 
    this.CloseCtiServer(); 
} 
private void menuItem_Hide_Click(object sender, System.EventArgs e) 
{ 
    this.HideCtiServer(); 
} 
private void CtiManiForm_SizeChanged(object sender, System.EventArgs e) 
{ 
if(    this.WindowState == FormWindowState.Minimized) 
{ 
    this.HideCtiServer(); 
} 
} 
private void notifyIcon1_DoubleClick(object sender,System.EventArgs e) 
{ 
    this.ShowCtiServer(); 
}

좋은 웹페이지 즐겨찾기