5.NotifyIcon

本视频主要介绍一个托盘控件。实现隐藏显示、右键响应、双击显示、图标变换的功能。
1.图标的变换

           private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();//隐藏
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();双击显示
        }

        private void showFormToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Show();右键显示
        }

        private void hideFormToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();右键隐藏
        }

2.图标变换
      private Icon oldIcon;//定义一个初始图标
        private void Form1_Load(object sender, EventArgs e)
        {
            oldIcon = notifyIcon1.Icon;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            notifyIcon1.Icon = Properties.Resources.setup;//图标变换为resource中的setup.ico
        }

        private void button3_Click(object sender, EventArgs e)
        {
            notifyIcon1.Icon = oldIcon;//变回原来的图标
        }

3.右键的关联
在NotifyIcon的 ContextStrip属性为右键的ID即可。

posted on 2008-02-22 13:46  爱你的人  阅读(176)  评论(0)    收藏  举报