webBrowser首次加载不能正确显示?

    ///


    /// 开启对COM的访问
    ///

    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            webBrowser1.ScriptErrorsSuppressed = true;
            webBrowser1.Navigate("about:blank");
            webBrowser1.Document.Write("
");
            //初始化页面
            webBrowser1.ObjectForScripting = this;
        }
        int bj = 1;
        ///
        /// 添加记录
        ///

        ///
        public void AddMsg(string strInfo)
        {
            object obj = new object();
            lock (obj)
            {
                string[] strRow = new string[]{
                            "
" +
                            bj.ToString()+"-"+strInfo+" 查看" +//查看后删掉
                            "
"};
                bj++;
                webBrowser1.Document.InvokeScript("AddMsg", strRow);
            }
        }
        ///
        /// 添加记录
        ///

        ///
        ///
        private void button1_Click(object sender, EventArgs e)
        {
            AddMsg("猜猜我是谁");
        }
        ///
        /// JS调必须为public
        ///

        ///
        public void DelMsg(object id)
        {
            MessageBox.Show(id.ToString());
        }

    }

你可能感兴趣的:(C#-WinForm应用,webbrowser,object,string,function,javascript,div)