1. <legend id='UFeKZ'><style id='UFeKZ'><dir id='UFeKZ'><q id='UFeKZ'></q></dir></style></legend>
    2. <small id='UFeKZ'></small><noframes id='UFeKZ'>

      <tfoot id='UFeKZ'></tfoot>
        <bdo id='UFeKZ'></bdo><ul id='UFeKZ'></ul>
      <i id='UFeKZ'><tr id='UFeKZ'><dt id='UFeKZ'><q id='UFeKZ'><span id='UFeKZ'><b id='UFeKZ'><form id='UFeKZ'><ins id='UFeKZ'></ins><ul id='UFeKZ'></ul><sub id='UFeKZ'></sub></form><legend id='UFeKZ'></legend><bdo id='UFeKZ'><pre id='UFeKZ'><center id='UFeKZ'></center></pre></bdo></b><th id='UFeKZ'></th></span></q></dt></tr></i><div id='UFeKZ'><tfoot id='UFeKZ'></tfoot><dl id='UFeKZ'><fieldset id='UFeKZ'></fieldset></dl></div>

      在 WebBrowser 控件的新选项卡中打开新网页

      时间:2023-06-04
          <bdo id='kLB6P'></bdo><ul id='kLB6P'></ul>

          <small id='kLB6P'></small><noframes id='kLB6P'>

          <tfoot id='kLB6P'></tfoot>

                <i id='kLB6P'><tr id='kLB6P'><dt id='kLB6P'><q id='kLB6P'><span id='kLB6P'><b id='kLB6P'><form id='kLB6P'><ins id='kLB6P'></ins><ul id='kLB6P'></ul><sub id='kLB6P'></sub></form><legend id='kLB6P'></legend><bdo id='kLB6P'><pre id='kLB6P'><center id='kLB6P'></center></pre></bdo></b><th id='kLB6P'></th></span></q></dt></tr></i><div id='kLB6P'><tfoot id='kLB6P'></tfoot><dl id='kLB6P'><fieldset id='kLB6P'></fieldset></dl></div>
                  <tbody id='kLB6P'></tbody>

                <legend id='kLB6P'><style id='kLB6P'><dir id='kLB6P'><q id='kLB6P'></q></dir></style></legend>
                本文介绍了在 WebBrowser 控件的新选项卡中打开新网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我在我的 c# 应用程序中使用 WebBrowser 控件,我想在其中打开网页.
                完全搞定了.

                I'm using WebBrowser control in my c# application, and I want to open web pages in it.
                It's completely done.

                我的问题:

                网页中目标为_blank的任何链接都将在新的IE窗口中打开.

                Any link in the web page that its target is _blank will open in new IE Window.

                我想在我的应用程序的新标签中打开此类链接.

                I'd like to open such link in new tab in my application.

                怎么做?

                谢谢!

                推荐答案

                private void Browser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
                {
                    var webBrowser = (WebBrowser)sender;
                    if (webBrowser.Document != null)
                    {
                        foreach (HtmlElement tag in webBrowser.Document.All)
                        {
                            if (tag.Id == null)
                            {
                                tag.Id = String.Empty;
                                switch (tag.TagName.ToUpper())
                                {
                                    case "A":
                                    {
                                        tag.MouseUp += new HtmlElementEventHandler(link_MouseUp);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                
                
                private void link_MouseUp(object sender, HtmlElementEventArgs e)
                {
                    var link = (HtmlElement)sender;
                    mshtml.HTMLAnchorElementClass a = (mshtml.HTMLAnchorElementClass)link.DomElement;
                    switch (e.MouseButtonsPressed)
                    {
                        case MouseButtons.Left:
                        {
                            if ((a.target != null && a.target.ToLower() == "_blank") || e.ShiftKeyPressed || e.MouseButtonsPressed == MouseButtons.Middle)
                            {
                                AddTab(a.href);
                            }
                            else
                            {
                                CurrentBrowser.TryNavigate(a.href);
                            }
                            break;
                        }
                        case MouseButtons.Right:
                        {
                            CurrentBrowser.ContextMenuStrip = null;
                            var contextTag = new ContextTag();
                            contextTag.Element = a;
                            contextHtmlLink.Tag = contextTag;
                            contextHtmlLink.Show(Cursor.Position);
                            break;
                        }
                    }
                }
                

                在 dotBrowser.sf.net 项目中查看更多信息

                See more at dotBrowser.sf.net project

                这篇关于在 WebBrowser 控件的新选项卡中打开新网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:复制 TabControl 选项卡 下一篇:如何使用 C# 启动具有特定 URL 的 Google Chrome 选项

                相关文章

                最新文章

                  • <bdo id='holsh'></bdo><ul id='holsh'></ul>
                1. <small id='holsh'></small><noframes id='holsh'>

                2. <tfoot id='holsh'></tfoot>

                    <i id='holsh'><tr id='holsh'><dt id='holsh'><q id='holsh'><span id='holsh'><b id='holsh'><form id='holsh'><ins id='holsh'></ins><ul id='holsh'></ul><sub id='holsh'></sub></form><legend id='holsh'></legend><bdo id='holsh'><pre id='holsh'><center id='holsh'></center></pre></bdo></b><th id='holsh'></th></span></q></dt></tr></i><div id='holsh'><tfoot id='holsh'></tfoot><dl id='holsh'><fieldset id='holsh'></fieldset></dl></div>
                    <legend id='holsh'><style id='holsh'><dir id='holsh'><q id='holsh'></q></dir></style></legend>