用 C# 编写一个停放在任务栏上的图标程序
来源:互联网 发布:三星手机官方软件 编辑:程序博客网 时间:2024/04/18 19:40
很简单,就不用说明了。
Form1.Designer.cs
namespace NotifyIconApplication
{
partial class Form1
{
/// <summary>
/// 設計工具所需的變數。
/// </summary>
private System.ComponentModel.IContainer components = null;
private bool IsShutDown = false;
/// <summary>
/// 清除任何使用中的資源。
/// </summary>
/// <param name="disposing">如果應該公開 Managed 資源則為 true,否則為 false。</param>
protected override void Dispose(bool disposing)
{
if (IsShutDown)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}
#region Windows Form 設計工具產生的程式碼
/// <summary>
/// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器修改這個方法的內容。
///
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(244, 172);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "隐藏窗体";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// notifyIcon1
//
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "这是我的测试程序,还Cool吧!";
this.notifyIcon1.Visible = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(198, 115);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(175, 13);
this.label1.TabIndex = 1;
this.label1.Text = "本程序使用Visual Studio .Net编写";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(566, 377);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.Label label1;
}
}
后台代码页 Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace NotifyIconApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//生成4个菜单项对象,显示文本分别为"显示窗口"、"隐藏窗口"、"执行程序"、"退出程序"
MenuItem menuItem1 = new MenuItem("显示窗口");
MenuItem menuItem2 = new MenuItem("隐藏窗口");
MenuItem menuItem3 = new MenuItem("执行程序");
MenuItem menuItem4 = new MenuItem("退出程序");
//分别为4个菜单项添加Click事件响应函数
menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//设置NotifyIcon对象的ContextMenu属性为生面的弹出菜单对象
notifyIcon1.ContextMenu = new ContextMenu(new MenuItem[] { menuItem1, menuItem2, menuItem3, menuItem4 });
//当用户双击程序图标时将执行相应的函数
notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon_DBClick);
this.FormClosing+=new FormClosingEventHandler(Form1_FormClosing);
this.Activated+=new EventHandler(Form1_Activated);
}
private void menuItem1_Click(object sender, System.EventArgs e)//“显示窗口”菜单的响应方法
{
this.Activate();//将窗口设定为当前活动窗口
//假如当前窗口没显示则显示当前窗口
if (this.Visible == false) this.Visible = true;
// //如果当前主窗口为最小化状态,将状态调整为Normal状态
if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
}
private void menuItem2_Click(object sender, System.EventArgs e)//"隐藏窗口"菜单的响应方法
{
if (this.Visible == true) this.Visible = false;//假如当前窗口为显示的则隐藏窗口
}
private void menuItem3_Click(object sender, System.EventArgs e)//"执行程序"菜单的响应方法
{
//显示一个提示信息框,表示事件已经得到响应
MessageBox.Show("演示程序已经执行,此处功能就是显示一个提示框!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void menuItem4_Click(object sender, System.EventArgs e)//“退出程序”菜单的响应方法
{
this.Close();//关闭当前对象(即窗体)
this.IsShutDown = true;
Application.Exit();//通过Application类的静态方法Exit()退出应用程序
}
private void button1_Click(object sender, System.EventArgs e)//用户单击按钮时的响应方法
{
this.Visible = false;//隐藏当前主窗口
}
private void notifyIcon_DBClick(object sender, System.EventArgs e)//用户双击应用程序图标进的响应方法
{
this.Activate();//将窗口设定为当前活动窗口
this.Visible = true;//显示当前主窗口
//如果当前主窗口为最小化状态,将状态调整为Normal状态
if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
}
private void Form1_FormClosing(object sender, System.EventArgs e)
{
this.IsShutDown = false;
this.Visible = false;
}
private void Form1_Activated(object sender, System.EventArgs e)
{
this.Show();
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace NotifyIconApplication
{
static class Program
{
/// <summary>
/// 應用程式的主要進入點。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
- 用 C# 编写一个停放在任务栏上的图标程序
- 用 C# 编写一个停放在任务栏上的图标程序
- 用 C# 编写一个停放在任务栏上的图标程序
- 如何隐藏一个程序在任务栏上图标
- 在C#中怎么让应用程序在任务栏上显示该程序的图标?
- [转贴]C#编写隐藏在任务栏图标的Windows应用程序
- 程序图标不显示在任务栏上
- 隐藏程序在任务栏的图标
- C# 实现任务栏图标程序
- C# 实现任务栏图标程序
- C# 实现任务栏图标程序
- C#编写最小化时隐藏为任务栏图标的
- C#编写最小化时隐藏为任务栏图标的
- 如何在Windows的任务栏的托盘上加一个快捷图标
- 将“在任务栏上出现的两个eclipse图标”合为一个
- 任务栏上不显示打开的程序图标
- VC编写任务栏右下角图标程序
- 浅谈c#实现隐藏任务栏图标的Windows托盘程序
- YCbCr-转载自百度
- C++中的预处理命令
- 笔记 03_传智播客hibernate教程_hibernate入门案例的代码优化
- jquery
- 另辟新径 domino 搞博客
- 用 C# 编写一个停放在任务栏上的图标程序
- PMP培训后的感悟分享
- VC6.0使用的18个技巧
- 软件测试之中文网络资源总汇
- vc6.0 注释多行代码
- 关于双路由
- 浮点型转换中文货币
- C#生成图片证件
- 繁体字网页解决方案