百度空间 | 百度首页 
 
查看文章
 
vs2008/c#/做1个exe程序/最小化在系统任务栏运行
2009年10月31日 星期六 16:02

要求生成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;
            };
        }
    }
}


类别:c#可执行程序 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu