当前位置:编程学习 > C#/ASP.NET >>

webBrowser的问题,大家帮帮我,弄了一天了!

我要用到webBrowser控件来显示javascript网页,我的js网页没有问题运行的很好,是有关高德地图的。但是在c#里面就显示不出地图,也不能用功能,不知道为什么。
弄了一下午了,真的真的恳请大家帮帮我,弄过地图大哥们更要看看啊~

namespace web浏览器
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            this.SetVisibleCore(true);
            this.FormBorderStyle = FormBorderStyle.Sizable;
            this.SetVisibleCore(true);
            
            webBrowser1.ScriptErrorsSuppressed = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string c = comboBox1.Text.ToString();
            webBrowser1.Navigate(c.ToString());
            comboBox1.Items.Add(c);
           
          
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("C:/Users/zyt/Documents/NetBeansProjects/web/web/busserch.html");
            //C:/Users/zyt/Documents/NetBeansProjects/web/web/temp.html
          //  webBrowser1.Url = new Uri("D:/1.htm");//指定要载入的网页
           
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
          
        }


    }
}


下面是js代码
********************************************************************************8
<script language="javascript">
     var mapObj, toolbar, overview, scale;
            function mapInit() {
                var opt = {
                    level : 17, //设置地图缩放级别
                    center : new AMap.LngLat(116.397428, 39.90923), //设置地图中心点
                    doubleClickZoom : true, //双击放大地图
                    scrollWheel : true//鼠标滚轮缩放地图
                }
                mapObj = new AMap.Map("iCenter", opt);
                mapObj.plugin(["AMap.ToolBar", "AMap.OverView", "AMap.Scale"], function() {
                    toolbar = new AMap.ToolBar();
                    toolbar.autoPosition = false;
                    //加载工具条
                    mapObj.addControl(toolbar);
                    overview = new AMap.OverView();
                    //加载鹰眼
                    mapObj.addControl(overview);
                    scale = new AMap.Scale();
                    //加载比例尺
                    mapObj.addControl(scale);
                });
               
            }
            function busSearch() {
                this.busSType = "s";
                //起始点
                this.cityname = "";
                this.start_x = "";
                this.start_y = "";
                this.start_name = "";
                this.start_address = "";
                this.start_tel = "";
                this.start_pid = "";
                this.start_citycode = "";
                this.start_cityname = "";
                this.start_detailLink = "";
                this.start_type = "";
                this.end_x = "";
                this.end_y = "";
                this.end_name = "";
                this.end_address = "";
                this.end_tel = "";
                this.end_pid = "";
                this.end_citycode = "";
                this.end_cityname = "";
                this.end_detailLink = "";
                this.end_type = "";
                this.x_array
                this.y_array
                this.x_c_array
                this.y_c_array
                this.xy_array
                this.xy_c_array
            }

var busS = new busSearch();
            function keywordSearch() {
                busS.cityname = document.getElementById("city").value;
                busS.start_name = document.getElementById("keyword").value;
                busS.end_name = document.getElementById("keyword1").value;
                var i = 1;
                var che = "";
                if (busS.cityname == "") {
                    che += i + ".请您输入城市\n";
                    i = i + 1;
                }
                if (busS.start_name == "") {
                    che += i + ".请您输入起点";
                    i = i + 1;
                }
                if (busS.end_name == "") {
                    che += i + ".请您输入终点";
                    i = i + 1;
                }
                if (i == 1) {
                    busS.busSType = "s";
                    busChange_search(busS.cityname, busS.start_name);
                } else {
                    alert(che);
                }
            }
            function busChange_search(city, keywords) {
                var PoiSearchOption = {
                    number : 10, //每页数量
                    batch : 1//请求页数
                };
                var MSearch = new AMap.PoiSearch(PoiSearchOption);
                MSearch.byKeywords(keywords, city, busChange_search_CallBack);
            }
            function busChange_search_CallBack(data) {
                if (busS.busSType == "s") {
                    if (data.list == null) {
                        document.getElementById("result").innerHTML = "起点未查找到任何结果!<br />建议:<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
                    } else {
                        busS.start_x = data.list[0].x;
                        busS.start_y = data.list[0].y;
                        busS.start_name = data.list[0].name;
                        busS.start_address = data.list[0].address;
                        busS.start_tel = data.list[0].tel;
                        busS.start_type = data.list[0].type;
                        busS.start_pid = data.list[0].pguid;
                        busS.start_citycode = data.list[0].citycode;
                        buschange_EndSearch();
                    }
                } else if (busS.busSType == "e") {
                    if (data.status == "E1") {
                        document.getElementById("result").innerHTML = "终点未查找到任何结果!<br />建议:<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";
                    } else {
                        busS.end_x = data.list[0].x;
                        busS.end_y = data.list[0].y;
                        busS.end_name = data.list[0].name;
                        busS.end_address = data.list[0].address;
                        busS.end_tel = data.list[0].tel;
                        busS.end_type = data.list[0].type;
                        busS.end_pid = data.list[0].pguid;
                        busS.end_citycode = data.list[0].citycode;
                        busChangeSearchXY();
                    }
                }
            }
            function buschange_EndSearch() {
                busS.busSType = "e";
                busChange_search(busS.cityname, busS.end_name);
            }
            function busChangeSearchXY() {
                var startXY = new AMap.LngLat(busS.start_x, busS.start_y);
                var endXY = new AMap.LngLat(busS.end_x, busS.end_y);
                var mrs = new AMap.BusSearch(BusSearchOption);
                var BusSearchOption = {
                    per : 100, //抽稀参数
                    batch : 1, //当前页码
                    number : 10//每页数量
                };
                var arr = new Array();
                //经纬度坐标数组
                arr.push(startXY);
                arr.push(endXY);
                var bus = new AMap.BusSearch(BusSearchOption);
                mrs.byTwoPoi(arr, busS.cityname, busChangeSearchXY_CallBack)
            }

额只能贴这么多。。
webBrowser javascript 地图 --------------------编程问答-------------------- 你的那个地图的html文件最好架设到IIS里面,然后再通过webBrowser加载页面。而不是直接导航到这个本地html文件。 --------------------编程问答-------------------- webBrowser1.Navigate(@"C:\Users\zyt\Documents\NetBeansProjects\web\web\busserch.html");
另外这个路径要存在。
补充:.NET技术 ,  组件/控件开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,