撞邪了!AxWebbrowser无法获取实时url!
程序代码:
求救!我的代码写得很清楚,导航完成后地址栏里会显示出URL,可是运行时却不是这样啊!怎么办? private void WebBrowser_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e) { this.tool2cmbURL.Text = WebBrowser.LocationURL; }我又将代码改成这样,还是没反应啊!!!!!!!!!
private void WebBrowser_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e) { tool2cmbURL.Text = (string)e.uRL; }
本人是在.net4.0 + win7下做的,求大虾帮助!!!!!!谢了!!!!
以下为全部代码,(别看着这么多,其实都很简单,我是新人,如果你觉得代码可以改进的话,欢迎指教,qq457561647)
///////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading ;
using System.Web;
namespace Weber
{
public partial class frmWeb : Form
{
public frmWeb()
{
InitializeComponent();
}
private void frmWeb_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
}
private void tool1btnGoBack_Click(object sender, EventArgs e)
{
try
{
WebBrowser.GoBack();
}
catch
{
MessageBox.Show("已经是最后一页!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void tool1btnGoForward_Click(object sender, EventArgs e)
{
try
{
WebBrowser.GoForward ();
}
catch
{
MessageBox.Show("已经是最前一页!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void tool1btnStop_Click(object sender, EventArgs e)
{
if (tool2cmbURL.Text == "") return;
if (tool2cmbURL.Text == "about:blank") return;
WebBrowser.Stop();
}
private void tool1btnRefresh_Click(object sender, EventArgs e)
{
if (tool2cmbURL.Text == "") return;
if (tool2cmbURL.Text == "about:blank") return;
WebBrowser.Refresh2();
}
private void tool1btnHome_Click(object sender, EventArgs e)
{
WebBrowser.GoHome();
}
private void mnFileNewForm_Click(object sender, EventArgs e)
{
frmWeb NewForm = new frmWeb();
NewForm.Show();
NewForm.Focus();
NewForm.WebBrowser.Navigate("about:blank");
}
private void WebBrowser_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
this.tool2cmbURL.Text = WebBrowser.LocationURL;
}
private void tool2cmbURL_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
tool2btnGO.PerformClick();
}
}
private void tool2btnGO_Click(object sender, EventArgs e)
{
if (tool2cmbURL.Text == "")
{
MessageBox.Show("请输入网址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (tool2cmbURL.Text == "about:blank")
{
MessageBox.Show("这是空白页,请输入网址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
Cursor.Current = Cursors.WaitCursor;
WebBrowser.Navigate(tool2cmbURL.Text);
Cursor.Current = Cursors.Default;
}
private void Search(string URL, string startwords)
{
string searchwords = tool2txt.Text.Trim();
if (searchwords.Length < 1)
{
WebBrowser.Navigate(URL);
return;
}
WebBrowser.Navigate(URL + startwords + HttpUtility.UrlEncode(Encoding.Default.GetBytes(searchwords)));
}
private void tool2btnSearch_Click(object sender, EventArgs e)
{
Search("http://www.baidu.com/", "s?wd=");
}
private void WebBrowser_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
string str = tool2cmbURL.Text.Trim();
}
private void WebBrowser_NewWindow2(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow2Event e)
{
frmWeb newwindow = new frmWeb();
e.ppDisp = newwindow.WebBrowser.Application;
newwindow.Show();
newwindow.WebBrowser.RegisterAsBrowser = true;
}
}
}