打印本文 打印本文 关闭窗口 关闭窗口
c# tabcontrol webbrowser 新标签页打开超链接
作者:佚名  文章来源:本站原创  点击数1996  更新时间:2012/8/27 17:12:53  文章录入:mintao  责任编辑:mintao
c# tabcontrol webbrowser 新标签页打开超链接

以下是代码片段:
#region 当右键点击在新窗口打开时打开新窗口
        void Form1_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
        {
            int index = bstrUrl.LastIndexOf("/");
            int index_s = bstrUrl.Length - 5;
            string domain = bstrUrl.Substring(index+1, index_s - index-1);
            Cancel = true;
            try
            {
                System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
                string strurl = webBrowser1.Document.ActiveElement.GetAttribute("href");
                wb.Url = new System.Uri(strurl, System.UriKind.Absolute);

                tabControl1.TabPages.Add(domain);
                wb.Dock = DockStyle.Fill;
                tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(wb);
            }
            catch
            {
            }
        }
        #endregion

打印本文 打印本文 关闭窗口 关闭窗口