托盘控件和微软图表控件

1.托盘控件代码示例:

在窗体加入notifyIcon控件,示例代码,点击托盘左键弹出窗体:

 public partial class Form1 : Form
    {
        private bool isClose;

        public Form1()
        {
            InitializeComponent();        
            ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip();
            ToolStripMenuItem startItem = new ToolStripMenuItem();
            startItem.Text = "开始";
            startItem.Image = Properties.Resources.Skype_16;
            startItem.Click += new EventHandler(startItem_Click);
            cms.Items.Add(startItem);
            ToolStripMenuItem stopItem= new ToolStripMenuItem();
            stopItem.Text = "终止";
            stopItem.Image = Properties.Resources.Head_OffLine;
            stopItem.Click += new EventHandler(stopItem_Click);
            cms.Items.Add(stopItem);
            ToolStripMenuItem exitItem = new ToolStripMenuItem();
            exitItem.Text = "退出";
            exitItem.Image = Properties.Resources.Head_OffLine;
            exitItem.Click += new EventHandler(exitItem_Click);
            cms.Items.Add(exitItem);
            notifyIcon.ContextMenuStrip = cms;              
        }

        void startItem_Click(object sender, EventArgs e)
        {
            
         }

        void stopItem_Click(object sender, EventArgs e)
        {

         }

        void exitItem_Click(object sender, EventArgs e)
        {
             isClose =true;
             Close();
         }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if(!isClose)
            {
                e.Cancel=true;
                this.Visible = false;
                this.notifyIcon.Visible = true;
            }
        }

        private void notifyIcon_Click(object sender, EventArgs e)
        {
            if ((e as MouseEventArgs).Button == MouseButtons.Left)
            {
                this.Visible = true;             
            }
        }

    }

实现的效果:


2.微软的图表控件,chart控件

实现效果如下:



教程可参照博客http://www.cnblogs.com/shuncy/archive/2008/11/07/1328738.html


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SysTray控件用法详解 VB SYSTRAY 托盘图标 用VB6自带的systray.ocx控件实现托盘图标程序 : 补充: 然后在自己的VB程序中添加改控件(工程-部件-浏览)。   最好把这个ocx放到C:\WINDOWS\system32。   改控件的属性InTray属性用来设置是否显示在托盘中,True为显示在托盘,False为不显示。TrayIcon属性是在托盘中显示的图标式样。TrayTip属性是鼠标移到改控件上面显示的提示文字。如果要使程序最小化时显示到托盘,如下:   Private Sub Form_Resize()    If Me.WindowState = vbMinimized Then    cSysTray1.InTray = True    Me.Visible = False End If   End Sub   点击托盘图标后让程序显示出来,如下:   Private Sub cSysTray1_MouseDown(Button As Integer, Id As Long)    Me.WindowState = vbNormal    Me.Visible = True    cSysTray1.InTray = False    Me.SetFocus   End Sub '单击关闭不退出程序 Private Sub Form_Unload(Cancel As Integer) 主程序.Hide Cancel = False End Sub '单击关闭不退出程序 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Cancel = 1 主程序.Hide End Sub ’tui为窗体菜单-退出选项名称 Private Sub tui_Click()’快捷键设ALT+F1 End End Sub '注:"主程序"代表一个窗体(Form),窗体菜单-退出选项需设置快捷键ALT+F1 '这个控件有一个小小的问题,如果托盘菜单有退出选项,不能直接用"End 语句",否则在编译后运行期间用户选择退出后,操作系统会报错,以上使用发送按键方法避免出错 ,当然还有其他避免出错方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值