问题一:就像QQ那样点最小化就缩小到右下角的系统栏里了。
解决方案 »
- 类、结构或接口成员声明中的标记“struct”无效
- 请问如何分批 密发 邮件?(用System.Net.Mail)
- DataGridView中怎么选定一个checkbox,不是多选
- 随机产生扑克点数与花色
- - -高手来帮我看看我哪里错了`
- 添加Web引用出了问题 ,那个比较熟的告诉一声
- 请问流媒体播放如何降低画质,提高性能
- 请教在c# winform里如何实现更换皮肤功能?
- 只想用C#进行WEB开发,是不是必须的装VS.net
- 请问,这是个什么怪异现象
- 在窗体上放了个NotifyIcon,想实现窗口最小化后隐藏,双击NotifyIcon后显视窗口并恢复大小!
- 没有分了,又没有办法,哭了.只好玩跳楼秀
添加一个ContextMenu,输入 需要的选择项
在NotifyIcon中的ContextMenu属性中 可以设置刚添加的ContextMenu
点托盘上的图标 就可以显示选择项
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.IO;namespace SendSMS
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
startSend sSend = new startSend(); public Form1()
{
InitializeComponent();
} #region
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion #region Windows Form 設計工具產生的程式碼
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.timer1 = new System.Windows.Forms.Timer(this.components);
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.contextMenu1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "簡訊勤務兵";
this.notifyIcon1.Visible = true;
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2,
this.menuItem3});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "打開簡訊勤務兵(&O)";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "-";
//
// menuItem3
//
this.menuItem3.Index = 2;
this.menuItem3.Text = "退出 (&X)";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// timer1
//
this.timer1.Interval = 60000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "簡訊勤務兵";
this.Load += new System.EventHandler(this.Form1_Load); }
#endregion #region 程序主入口
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
#endregion #region 重寫WndProc屏蔽掉關閉按鈕
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
{
// User clicked close button
//this.WindowState = FormWindowState.Minimized;
this.Visible = false;
return;
}
base.WndProc (ref m);
}
#endregion #region 退出簡訊勤務兵
private void menuItem3_Click(object sender, System.EventArgs e)
{
DialogResult result;
result = MessageBox.Show(this,"你確定要退出簡訊勤務兵麼?","簡訊勤務兵...",MessageBoxButtons.OKCancel,MessageBoxIcon.Asterisk); //"簡訊勤務兵..."
if(result == DialogResult.OK)
{
this.Dispose();
this.Close();
}
}
#endregion #region 顯示簡訊勤務兵
private void menuItem1_Click(object sender, System.EventArgs e)
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Visible = true;
//this.WindowState = FormWindowState.Normal;
}
#endregion #region 雙擊托盤圖標
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Visible = true;
}
#endregion #region Form1_load
private void Form1_Load(object sender, System.EventArgs e)
{// this.timer1.Interval = 60000;
// this.timer1.Start();
this.Visible = true; sSend.ifHaveSend();
}
#endregion #region 定時事件
public int h = 0;
private void timer1_Tick(object sender, System.EventArgs e)
{
sSend.ifHaveSend();
}
#endregion
}
}
使用NotifyIcon
在窗体的最小化消息(在event里找不到)将窗体.hide()
添加NotifyIcon的单击事件 这个时候将显示窗体.show()具体代码已经有很多了 搜一下
//在最大化菜单事件中
this.WindowState = FormWindowState.Normal;//(FormWindowState.Maximized)//在最小化菜单事件中
this.WindowState = FormWindowState.Minimized;仅供参考,呵呵~~~