“WebBrowser”控件是不是根据网址,在浏览器中打开网页啊???也就是“webBrowser1.Navigate(new Uri("www.csdn.com", UriKind.RelativeOrAbsolute));”,是不是可以在浏览器中打开CSDN.如果不可以,那么要在软件中知道百度地址,怎样用webBrowser打开呢???

解决方案 »

  1.   

    是的,直接用 
    webBrowser1.Navigate(textBox1.Text);
    textBox1里面写着想要浏览的网址
      

  2.   

    这样试试
    public BrowserPage()
      {
      InitializeComponent();
      this.Loaded += new RoutedEventHandler(BrowserPage_Loaded);
      }
     private void BrowserPage_Loaded(object sender, RoutedEventArgs e)
      {
      if (NavigationContext.QueryString.Count > 0)
      {
      string url = "http://www.google.com"
      webBrowser1.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
      }  
      }
      

  3.   

     public BrowserPage()
            {
                InitializeComponent();
                Browser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(Browser_Navigated);
                Browser.Navigating += new EventHandler<NavigatingEventArgs>(Browser_Navigating);
                Browser.ScriptNotify += new EventHandler<NotifyEventArgs>(Browser_ScriptNotify);
                this.Loaded += new RoutedEventHandler(BrowserPage_Loaded);
            }        void Browser_ScriptNotify(object sender, NotifyEventArgs e)
            {
                Browser.Navigate(new Uri(e.Value, UriKind.Absolute));
            }        void Browser_Navigating(object sender, NavigatingEventArgs e)
            {
                ProgBar.Visibility = Visibility.Visible;
            }        void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
            {
                ProgBar.Visibility = Visibility.Collapsed;
            }        private void BrowserPage_Loaded(object sender, RoutedEventArgs e)
            {
                if (NavigationContext.QueryString.Count > 0)
                {
                    string url = NavigationContext.QueryString["url"];
                    Browser.Navigate(new Uri(url, UriKind.Absolute));
                    Browser.IsScriptEnabled = true;
                }         }
      

  4.   

    楼主这个应该很简单,我03年用VS2003 实现的一个例子你参考下。这个很简单:
    WebBrowser控件功能很强大,能够实现断网检测,启动页面,页面跳转,页面控制;网页与CS程序交互等方面。目前银行、电信自助设备使用此项功能。
      

  5.   

    有个例子你看下:VS2003 实现
    private void WebMainNavigate(string strURL)
    {
    Object o = null;
    axWebBrowser1.Navigate(strURL, ref o, ref o, ref o, ref o);
    }
    private void axWebBrowser1_NavigateError(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateErrorEvent e)
    {
      Log("Erro", "检测到断网,进入打开本地页面地址:"+m_offline_main);
        WebMainNavigate(m_offline_main);
    //MessageBox.Show(e.uRL.ToString());
    } private void ShowOfflineMain()
    {
    Log("Messg", "调用打开主页面地址:"+m_URL);
    WebMainNavigate(m_URL);
    }
    Log("Messg", "启动定制浏览器!");
    this.axWebBrowser1.Dock = DockStyle.None;
    this.axWebBrowser1.Top = -2;
    this.axWebBrowser1.Height = this.Height + 30;
    this.axWebBrowser1.Left = -2;
    this.axWebBrowser1.Width = this.Width + 4; 
    Cursor.Current = Cursors.WaitCursor; 
    if(!loadini())
    {   Log("Erro", "请关闭程序,配置断网网页!");
    MessageBox.Show("请关闭程序,配置断网网页!");
    return;
    }
    System.Threading.Thread.Sleep(5000) ;
    ShowOfflineMain();
    Cursor.Current = Cursors.Default ;
      

  6.   

    private void Form1_Load(object sender, System.EventArgs e)
    {
    //loadini();
    Log("Messg", "启动定制浏览器!");
    this.axWebBrowser1.Dock = DockStyle.None;
    this.axWebBrowser1.Top = -2;
    this.axWebBrowser1.Height = this.Height + 30;
    this.axWebBrowser1.Left = -2;
    this.axWebBrowser1.Width = this.Width + 4; 
    Cursor.Current = Cursors.WaitCursor; 
    if(!loadini())
    {   Log("Erro", "请关闭程序,配置断网网页!");
    MessageBox.Show("请关闭程序,配置断网网页!");
    return;
    }
    System.Threading.Thread.Sleep(5000) ;
    ShowOfflineMain();
    Cursor.Current = Cursors.Default ;

    }