winfrom中WebBrowser调用本地html

相关涉及汇总:

C#Webbrowser屏蔽弹出窗口及脚本错误提示 -> http://blog.csdn.net/wonsoft/article/details/5197015

C# webbrowser中新窗口在Webbrowser内打开屏蔽网页JS错误 -> http://blog.csdn.net/jiangqin115/article/details/40710883


winfrom中WebBrowser调用本地html_第1张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace localindex
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.ScriptErrorsSuppressed = true; //禁用错误脚本提示
            webBrowser1.IsWebBrowserContextMenuEnabled = false; // 禁用右键菜单
            webBrowser1.WebBrowserShortcutsEnabled = false; //禁用快捷键
            webBrowser1.AllowWebBrowserDrop = false; // 禁止文件拖动
            
            webBrowser1.Navigate(Application.StartupPath + @"\assets\index.html");
            webBrowser1.Navigated += WebBrowserNavigatedEventHandler;
            webBrowser1.DocumentCompleted += WebBrowserDocumentCompletedEventHandler;
            webBrowser1.Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error);
            webBrowser1.NewWindow += CancelEventHandler;
        }

        //禁用新窗口打开
        public void CancelEventHandler(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void Window_Error(object sender, HtmlElementErrorEventArgs e)
        {
            e.Handled = true;
        }

        //后发生
        public void WebBrowserDocumentCompletedEventHandler(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            MessageBox.Show("DocumentCompleted");
        }

        //先发生
        public void WebBrowserNavigatedEventHandler(object sender, WebBrowserNavigatedEventArgs e)
        {
            MessageBox.Show("Navigated");
        }
    }
}

winfrom中WebBrowser调用本地html_第2张图片

你可能感兴趣的:(Winfrom)