欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# WinForm窗口最小化到系統(tǒng)托盤

 更新時(shí)間:2008年11月26日 12:40:50   作者:  
C#編寫最小化時(shí)隱藏為任務(wù)欄圖標(biāo)的 Window appllication.
1.設(shè)置WinForm窗體屬性showinTask=false
2.加notifyicon控件notifyIcon1,為控件notifyIcon1的屬性Icon添加一個(gè)icon圖標(biāo)。
3.添加窗體最小化事件(首先需要添加事件引用):

復(fù)制代碼 代碼如下:

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.添加點(diǎn)擊圖標(biāo)事件(首先需要添加事件引用):

private void notifyIcon1_Click(object sender, EventArgs e)
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}
5.可以給notifyIcon添加右鍵菜單:
主窗體中拖入一個(gè)ContextMenu控件NicontextMenu,點(diǎn)中控件,在上下文菜單中添加菜單,notifyIcon1的ContextMenu行為中選中NicontextMenu 作為上下文菜單。
復(fù)制代碼 代碼如下:

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 = "關(guān)于 ";
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();
}

相關(guān)文章

  • C#算法之回文數(shù)

    C#算法之回文數(shù)

    這篇文章介紹了C#算法之回文數(shù),文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-01-01
  • CefSharp如何進(jìn)行頁面的縮放(Ctrl+滾輪)

    CefSharp如何進(jìn)行頁面的縮放(Ctrl+滾輪)

    CefSharp簡單來說就是一款.Net編寫的瀏覽器包,本文主要介紹了CefSharp如何進(jìn)行頁面的縮放,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • C#中調(diào)用Servlet示例

    C#中調(diào)用Servlet示例

    這篇文章主要介紹了C#中調(diào)用Servlet示例,本文實(shí)現(xiàn)通用消息接口使用servlet作為服務(wù)器端服務(wù)接口,第三方應(yīng)用程序通過http post的方式調(diào)用servlet,實(shí)現(xiàn)與通用消息接口的調(diào)用連接,需要的朋友可以參考下
    2015-05-05
  • C#中的delegate委托類型基本學(xué)習(xí)教程

    C#中的delegate委托類型基本學(xué)習(xí)教程

    這篇文章主要介紹了C#中的delegate委托類型基本學(xué)習(xí)教程,委托是C#語言所具有的一個(gè)重要特性,需要的朋友可以參考下
    2016-01-01
  • C#泛型用法實(shí)例分析

    C#泛型用法實(shí)例分析

    這篇文章主要介紹了C#泛型用法,實(shí)例分析了C#泛型的功能、定義與使用技巧,需要的朋友可以參考下
    2015-06-06
  • C#高效反射調(diào)用方法類實(shí)例詳解

    C#高效反射調(diào)用方法類實(shí)例詳解

    在本篇文章中小編給大家分享的是關(guān)于C#高效反射調(diào)用方法類的相關(guān)實(shí)例內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2019-07-07
  • C#讀寫txt文件多種方法實(shí)例代碼

    C#讀寫txt文件多種方法實(shí)例代碼

    這篇文章主要介紹了C#讀寫txt文件的小例子,大家可以參考使用
    2013-11-11
  • C#如何修改項(xiàng)目名圖文詳解

    C#如何修改項(xiàng)目名圖文詳解

    最近開發(fā)工作接近尾聲,客戶來要求更換項(xiàng)目的名稱,差不多要變更整個(gè)解決方案中項(xiàng)目名稱,引用等等,這個(gè)工作量還是很大的,這篇文章主要給大家介紹了關(guān)于C#如何修改項(xiàng)目名的相關(guān)資料,需要的朋友可以參考下
    2023-01-01
  • Unity實(shí)現(xiàn)俄羅斯方塊游戲

    Unity實(shí)現(xiàn)俄羅斯方塊游戲

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)俄羅斯方塊游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • C# 開發(fā)日志本地化工具

    C# 開發(fā)日志本地化工具

    這篇文章主要介紹了C# 開發(fā)日志本地化工具的步驟,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-02-02

最新評論