zoukankan      html  css  js  c++  java
  • C#实现托盘应用程序

    下面是我根据网络上的应用程序改编的一个简单的托盘程序的DEMO,实现了一般托盘程序的基本功能

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsApplication4
    {
        public partial class Form1 : Form
        {

            private Icon mNetIcon = new Icon("appMain.ico");

            private NotifyIcon TrayIcon;

            private ContextMenu notifyiconMnu;


            public Form1()
            {
                InitializeComponent();
                Initializenotifyicon();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.WindowState = System.Windows.Forms.FormWindowState.Minimized;


            }

            private void Initializenotifyicon()
            {
                //设定托盘程序的各个属性
                TrayIcon = new NotifyIcon();
                TrayIcon.Icon = mNetIcon;
                TrayIcon.Text = "用Visual C#做托盘程序";
                TrayIcon.Visible = true;
                TrayIcon.Click += new System.EventHandler(this.click);

                ////定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
                MenuItem[] mnuItms = new MenuItem[1];
                mnuItms[0] = new MenuItem();
                mnuItms[0].Text = "退出系统";
                mnuItms[0].Click += new System.EventHandler(this.showmessage);

                notifyiconMnu = new ContextMenu(mnuItms);
                TrayIcon.ContextMenu = notifyiconMnu;
                ////为托盘程序加入设定好的ContextMenu对象
            }

            private void Form1_FormClosed(object sender, FormClosedEventArgs e)
            {
                TrayIcon.Visible = false;
            }
            public void click(object sender, System.EventArgs e)
            {
                MessageBox.Show("Visual C#编写托盘程序中的事件响应");
            }

            public void showmessage(object sender, System.EventArgs e)
            {
                MessageBox.Show("你选择了退出系统!");
                this.Close();
            }

        }
    }

  • 相关阅读:
    翻String.Format源码发现的新东西:StringBuilderCache
    禁止Asp.Net WebService 的Test页面功能
    利用XML序列化和Asp.Net Web缓存实现站点配置文件
    使用.NET配置文件appSettings元素的File属性
    <probing> 元素指定扩展Asp.Net加载程序集位置
    Windbg .net内存调试有用的命令(笔记 )
    The Dangers of the Large Object Heap(转载,LOH内存碎片情景重现)
    Advanced .NET Debugging: Managed Heap and Garbage Collection(转载,托管堆查内存碎片问题解决思路)
    调试.NET程序OutOfMemoryException (转载)
    mysql数据库之索引和分析索引
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/1699877.html
Copyright © 2011-2022 走看看