1:新建winform项目
2:安装cefSharp
3:配置管理器更改为X86
4:添加引用
using CefSharp;
using CefSharp.WinForms;
5:项目启动,打开网页
/// <summary>
/// 创建ChromiumWebBrowser 实例
/// </summary>
public ChromiumWebBrowser browser;
public Form1()
{
InitializeComponent();
browser = new ChromiumWebBrowser("http://www.baidu.com/");
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
6:项目启动窗口最大化
/// <summary>
/// 窗口加载最大化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
WindowState = FormWindowState.Maximized;
}
7:取消关闭事件,最小化到托盘
1>:添加notifyIcon 控件
2:///
/// 窗口关闭事件,最小化到托盘
///
///
///
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
notifyIcon1.Visible = true;
this.Hide();
return;
}
8:添加contextMenuStrip 控件,使用notifyIcon 添加绑定到contextMenuStrip
9:添加菜单点击事件
10:
///
/// 显示窗口
///
///
///
private void Show_Click(object sender, EventArgs e)
{
notifyIcon1.Visible = false;
this.Show();
WindowState = FormWindowState.Maximized;
this.Focus();
}
///
/// 退出窗口
///
///
///
private void Close_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
this.Dispose();
this.Close();
}
}
源代码链接:https://pan.baidu.com/s/19kr8UjF1xNmeXJB5SstE6Q 提取码:bx40