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

【高悬赏】VS - C# 编程,请教WebBrowser控件的使用方法。

我想在窗体中加一个浏览器,在TextBox控件中输入网址,按下Button后在WebBrowser中网页内容。怎么写?要简洁一点.........呃...
答案:
// Navigates to the URL in the address box when
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Navigate(toolStripTextBox1.Text);
}
}

// Navigates to the URL in the address box when
// the Go button is clicked.
private void goButton_Click(object sender, EventArgs e)
{
Navigate(toolStripTextBox1.Text);
}

// Navigates to the given URL if it is valid.
private void Navigate(String address)
{
if (String.IsNullOrEmpty(address)) return;
if (address.Equals("about:blank")) return;
if (!address.StartsWith("http://") &&
!address.StartsWith("https://"))
{
address = "http://" + address;
}
try
{
webBrowser1.Navigate(new Uri(address));
}
catch (System.UriFormatException)
{
return;
}
}

// Updates the URL in TextBoxAddress upon navigation.
private void webBrowser1_Navigated(object sender,
WebBrowserNavigatedEventArgs e)
{
toolStripTextBox1.Text = webBrowser1.Url.ToString();
}




替换地址即可


MSDN http://msdn.microsoft.com/zh-cn/library/system.windows.forms.webbrowser(VS.80).aspx
去百度C#吧看看
得加分啊

上一个:C# windows 编程
下一个:C# 网络编程

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,