最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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#委托與事件(詳解)

    c#委托與事件(詳解)

    本文中,我將通過(guò)兩個(gè)范例由淺入深地講述什么是委托、為什么要使用委托、事件的由來(lái)、.Net Framework中的委托和事件、委托和事件對(duì)Observer設(shè)計(jì)模式的意義,對(duì)它們的中間代碼也做了討論
    2021-07-07
  • C#項(xiàng)目中跨文件調(diào)用公共類的實(shí)例方法

    C#項(xiàng)目中跨文件調(diào)用公共類的實(shí)例方法

    在本篇文章里小編給大家整理的是關(guān)于C#項(xiàng)目中如何跨文件調(diào)用公共類的知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。
    2019-08-08
  • C#實(shí)現(xiàn)同步模式下的端口映射程序

    C#實(shí)現(xiàn)同步模式下的端口映射程序

    這篇文章介紹了C#實(shí)現(xiàn)同步模式下的端口映射程序,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • WPF運(yùn)行時(shí)替換方法實(shí)現(xiàn)mvvm自動(dòng)觸發(fā)刷新

    WPF運(yùn)行時(shí)替換方法實(shí)現(xiàn)mvvm自動(dòng)觸發(fā)刷新

    這篇文章主要為大家詳細(xì)介紹了WPF運(yùn)行時(shí)如何實(shí)現(xiàn)setter不需要調(diào)方法就可以自動(dòng)觸發(fā)界面刷新,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-04-04
  • C#連接SQL?Sever數(shù)據(jù)庫(kù)詳細(xì)圖文教程

    C#連接SQL?Sever數(shù)據(jù)庫(kù)詳細(xì)圖文教程

    C#是Microsoft公司為.NET Framework推出的重量級(jí)語(yǔ)言,和它搭配最完美的數(shù)據(jù)庫(kù)無(wú)疑就是Microsoft SQL Server了,下面這篇文章主要給大家介紹了關(guān)于C#連接SQL?Sever數(shù)據(jù)庫(kù)的詳細(xì)圖文教程,需要的朋友可以參考下
    2023-06-06
  • C#實(shí)現(xiàn)DataTable,List和Json轉(zhuǎn)換的方法

    C#實(shí)現(xiàn)DataTable,List和Json轉(zhuǎn)換的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)DataTable,List和Json轉(zhuǎn)換的方法,結(jié)合實(shí)例形式分析了DataTable、list、DataReader、DataSet等轉(zhuǎn)換成JSON的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-08-08
  • C#多線程系列之多階段并行線程

    C#多線程系列之多階段并行線程

    本文詳細(xì)講解了C#多線程的多階段并行線程,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • 使用C#實(shí)現(xiàn)Windows組和用戶管理的示例代碼

    使用C#實(shí)現(xiàn)Windows組和用戶管理的示例代碼

    這篇文章主要介紹了使用C#實(shí)現(xiàn)Windows組和用戶管理的示例代碼,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2021-01-01
  • 淺析WPF中ToolTip工具提示的應(yīng)用

    淺析WPF中ToolTip工具提示的應(yīng)用

    在日常應(yīng)用中,當(dāng)鼠標(biāo)放置在某些控件上時(shí),都會(huì)有相應(yīng)的信息提示,從軟件易用性上來(lái)說(shuō),這是一個(gè)非常友好的功能設(shè)計(jì),本文就來(lái)和大家簡(jiǎn)單聊聊WPF中ToolTip工具提示的相關(guān)使用,有興趣的可以了解下
    2023-12-12
  • Unity編輯器資源導(dǎo)入處理函數(shù)OnPreprocessAudio用法示例

    Unity編輯器資源導(dǎo)入處理函數(shù)OnPreprocessAudio用法示例

    這篇文章主要為大家介紹了Unity編輯器資源導(dǎo)入處理函數(shù)OnPreprocessAudio用法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08

最新評(píng)論

西乌珠穆沁旗| 新郑市| 康定县| 天等县| 黔东| 南京市| 宁强县| 邯郸市| 界首市| 湖南省| 苍梧县| 平武县| 迭部县| 玛纳斯县| 威海市| 凤冈县| 白银市| 阿巴嘎旗| 武城县| 长海县| 金门县| 阿拉善右旗| 荆州市| 漳浦县| 沙河市| 彭州市| 泰安市| 铁岭县| 永登县| 乳山市| 太谷县| 灵山县| 凌海市| 绥宁县| 佳木斯市| 涞水县| 松滋市| 克拉玛依市| 嘉义市| 金门县| 花莲市|