要求生成1个exe的程序(仅1个程序,不用安装不用修改注册表,点击就运行),运行后弹出的窗体里是baidu.com这个页面,搜索时也在这个窗体下,点击窗体上的最小化时,把程序转到系统托盘,任务栏不显示。
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//添加 WebBrowser 控件
WebBrowser browser = new WebBrowser();
browser.Dock = DockStyle.Fill;
browser.Url = new Uri("http://www.baidu.com/");
browser.NewWindow += delegate(object sender2, CancelEventArgs e2)
{
e2.Cancel = true;
browser.Navigate(browser.StatusText);
};
this.Controls.Add(browser);
//添加托盘图标
NotifyIcon icon = new NotifyIcon();
icon.Icon = this.Icon;
icon.Visible = true;
icon.DoubleClick += delegate
{
this.Visible = true;
this.WindowState = FormWindowState.Maximized;
};
//窗体最大化
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Maximized;
this.SizeChanged += delegate
{
if (this.WindowState == FormWindowState.Minimized)
this.Visible = false;
};
this.FormClosed += delegate
{
icon.Visible = false;
};
}
}
}