托盘问题,谢谢各位大虾。。。
小弟刚从DELPHI转过来,学C#不久,听介绍C#有个专门做托盘的控件,偶找了一些资料,可能是俺太笨,不得要解,希望那位大虾帮帮小弟,做个DEMO给小弟。谢谢!
E_mail:zdq801104@tom.com
问题点数:80、回复次数:7Top
1 楼yangxd_yi(杨一)回复于 2005-02-04 08:42:07 得分 40
看看这篇文章,对你应该有帮助,
http://www.vchome.net/dotnet/dotnetdocs/dotnet39.htm
帮你顶一下...Top
2 楼xzhy80(算了吧,散了吧)回复于 2005-02-04 08:50:29 得分 5
upTop
3 楼FJGoodGood(_FJ_强中强)回复于 2005-02-04 08:55:30 得分 20
给你个我作的例子:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace test
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 40);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "点击我最小化";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.contextMenu1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "我的应用程序";
this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "复原";
this.menuItem1.Click += new System.EventHandler(this.notifyIcon1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 269);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.VisibleChanged += new System.EventHandler(this.Form1_VisibleChanged);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.Hide();
}
private void Form1_VisibleChanged(object sender, System.EventArgs e)
{
notifyIcon1.Visible = !this.Visible; // 如果窗口显示,托盘托表就不显示,如果窗口隐藏,托盘图标就显示
}
private void notifyIcon1_Click(object sender, System.EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}
Top
4 楼lzoxl(落花人独立,微雨雁双飞)回复于 2005-02-04 08:56:28 得分 5
notifyicon控件Top
5 楼skytear()回复于 2005-02-04 08:57:29 得分 5
upTop
6 楼zdq801104(【☆这个杀手不太冷☆】)回复于 2005-02-04 08:58:54 得分 0
谢谢各位大虾,特别是yangxd_yi(杨一) AND FJGoodGood(_FJ_强中强)Top
7 楼hawk234(鹰)回复于 2005-02-04 09:03:04 得分 5
upTop




