winform + cefSharp achieve the form is loaded browser

1: New winform Project
2: Installation cefSharp

3: Change Configuration Manager X86

4: Add a reference to
a using CefSharp;
a using CefSharp.WinForms;
5: start of the project, open the page

    /// <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: Project start maximized window

     /// <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: Cancel the shutdown event, Minimize to Tray
1>: Add notifyIcon Control
2: ///


/// window closing event, Minimize to tray
///

///
///
Private void Form1_FormClosing (Object SENDER, FormClosingEventArgs E)
{
the e.Cancel = to true;
this.WindowState = FormWindowState.Minimized;
notifyIcon1.Visible = to true;
this.Hide ();
return;
}
. 8: Add contextMenuStrip control, use notifyIcon added to bind to the ContextMenuStrip

9: adding menu click event

10:
///
/// display window
///

///
///
private void Show_Click(object sender, EventArgs e)
{
notifyIcon1.Visible = false;
this.Show();
WindowState = FormWindowState.Maximized;
this.Focus();
}
///
/// exit window
///

///
///
private void Close_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
this.Dispose();
this.Close();
}
}

Source link: https://pan.baidu.com/s/19kr8UjF1xNmeXJB5SstE6Q extraction code: bx40

Guess you like

Origin www.cnblogs.com/WlxjSan/p/11798055.html