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();
            }

        }
    }

  • 相关阅读:
    数组和字符串长度length
    Eclipse最有用快捷键整理
    Eclipse编辑java文件报Unhandled event loop exception错误的解决办法
    Java 删除项目中的.svn信息
    oracle 删除外键约束 禁用约束 启用约束
    Java Sftp上传下载文件
    java 如何判断操作系统是Linux还是Windows
    Javascript-正则表达式-开发中的使用.
    Eclipse和PyDev搭建完美Python开发环境 Windows篇
    ExtJS4为form表单必填项添加红色*标识
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/1699877.html
Copyright © 2011-2022 走看看