wpf 网络浏览器控件和谷歌地图,叠加灰色图像 [英] wpf webbrowser control and google maps, overlays gray image

查看:27
本文介绍了wpf 网络浏览器控件和谷歌地图,叠加灰色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#中的webbrowser控件渲染谷歌地图已经很久了.最近,谷歌地图现在加载,然后覆盖一个灰色框.看图

I have been using the webbrowser control in c# to render google maps for a long time. Recently, google maps now loads up and then a gray box is overlaid. See the image

http://www.condoresorts.com/Debug/webdebug.png

有没有人知道是什么导致了这种情况?

Anyone have the slightest idea what would cause this?

this.webBrowser1.DocumentText = @"<iframe width=""425"" height=""350"" frameborder=""0"" scrolling=""no"" marginheight=""0"" marginwidth=""0"" src=""https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed""></iframe><br /><small><a href=""https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7"" style=""color:#0000FF;text-align:left"">View Larger Map</a></small>";

Noseratio 是正确的.我跟着他的链接,实现了项目的代码,它不再有这种行为.

Noseratio was correct. I followed his link, implemented the code for the project and it no long had that behavior.

amespace WebBroweerControls{公开课 Form1{System.Windows.Forms.WebBrowser webBrowser1 = null;

amespace WebBroweerControls { public class Form1 { System.Windows.Forms.WebBrowser webBrowser1 = null;

    public Form1(System.Windows.Forms.WebBrowser br)
    {

        webBrowser1 = br;

        SetBrowserFeatureControl();



    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //DoNavigationAsync().ContinueWith(_ =>
        //{
        //    MessageBox.Show("Navigation complete!");
        //}, TaskScheduler.FromCurrentSynchronizationContext());


        //var html = "<iframe width=\"425\" height=\"350\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" " +
        //       "src=\"https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;" +
        //       "geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471," +
        //       "-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed\">" +
        //       "</iframe>" +
        //       "<br /><small><a href=\"https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas" +
        //       "&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;" +
        //       "sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7\" style=\"color:#0000FF;" +
        //       "text-align:left\">View Larger Map</a></small>";

        webBrowser1.Navigate("http://www.condoresorts.com/Directions/PrintShares/Coyote%20Lakes/Pillars%20to%20Coyote%20Lakes.htm");
    }

    private async Task DoNavigationAsync()
    {
        TaskCompletionSource<bool> documentCompleteTcs = null;

        WebBrowserDocumentCompletedEventHandler handler = delegate
        {
            if (documentCompleteTcs.Task.IsCompleted)
                return;
            documentCompleteTcs.SetResult(true);
        };

        documentCompleteTcs = new TaskCompletionSource<bool>();
        this.webBrowser1.DocumentCompleted += handler;

        // could do this.wb.Navigate(url) here 
        this.webBrowser1.DocumentText = "<!DOCTYPE html><head><meta http-equiv='X-UA-Compatible' content='IE=edge'/></head>" +
            "<body><input size=50 type='text' placeholder='HTML5 if this placeholder is visible'/></body>";

        await documentCompleteTcs.Task;
        this.webBrowser1.DocumentCompleted -= handler;

        dynamic document = this.webBrowser1.Document.DomDocument;
        dynamic navigator = document.parentWindow.navigator;
        var info =
            "\n navigator.userAgent: " + navigator.userAgent +
            "\n navigator.appName: " + navigator.appName +
            "\n document.documentMode: " + document.documentMode +
            "\n document.compatMode: " + document.compatMode;

        MessageBox.Show(info);
    }

    private static void SetBrowserFeatureControl()
    {
        // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

        // WebBrowser Feature Control settings are per-process
        var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);

        // make the control is not running inside Visual Studio Designer
        if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0)
            return;

        SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode());
    }

    private static void SetBrowserFeatureControlKey(string feature, string appName, uint value)
    {
        using (var key = Registry.CurrentUser.CreateSubKey(
            String.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature),
            RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
            key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord);
        }
    }

    private static UInt32 GetBrowserEmulationMode()
    {
        int browserVersion = 7;
        using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer",
            RegistryKeyPermissionCheck.ReadSubTree,
            System.Security.AccessControl.RegistryRights.QueryValues))
        {
            var version = ieKey.GetValue("svcVersion");
            if (null == version)
            {
                version = ieKey.GetValue("Version");
                if (null == version)
                    throw new ApplicationException("Microsoft Internet Explorer is required!");
            }
            int.TryParse(version.ToString().Split('.')[0], out browserVersion);
        }

        // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
        UInt32 mode = 10000;

        switch (browserVersion)
        {
            case 7:
                // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
                mode = 7000;
                break;
            case 8:
                // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
                mode = 8000;
                break;
            case 9:
                // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                mode = 9000;
                break;
            default:
                // use IE10 mode by default
                break;
        }

        return mode;
    }
}

}

刚刚实例化了这个类并将它提供给我的浏览器控件:

Just instantiated this class and fed it my webbrowser control:

WebBroweerControls.Form1 f1 = new WebBroweerControls.Form1(this.webBrowser1);

WebBroweerControls.Form1 f1 = new WebBroweerControls.Form1(this.webBrowser1);

推荐答案

请尝试以下...

 var html = "<iframe width=\"425\" height=\"350\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" " +
                   "src=\"https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;" +
                   "geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471," +
                   "-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed\">" +
                   "</iframe>" +
                   "<br /><small><a href=\"https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas" +
                   "&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;" +
                   "sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7\" style=\"color:#0000FF;" +
                   "text-align:left\">View Larger Map</a></small>";

 webBrowser1.NavigateToString(html);

基本上相同的代码...只是使用 NavigateToString() 将 html 参数加载到 WebBrowser.

Basically the same code... Just used NavigateToString() to load the html parameter to WebBrowser.

这篇关于wpf 网络浏览器控件和谷歌地图,叠加灰色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆