System.Windows.Forms.WebBrowser 类以下代码摘自 MSDN:// 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();
}
// 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();
}
解决方案 »
- 谁有好点的c#视频教程么,给个下载地址,谢了
- 读图片的绝对路径
- 瞧点的问题
- 如何打开ODBC data source administrator窗口并的到 连接字符串? 强人进 100分相送
- 大侠:net控件台程序中的相对路径应该怎么取得呀,急用,请大侠帮帮忙
- 救命!如何用Window程序使打开的IE转向其他页面?
- openiffice转换附件格式为pdf,怎么加入jegp压缩的质量选择
- 如何实现点击键盘的TAB键使界面上的光标移到下一项?
- 请各位说说,哪里有好的win服务程序开发的教材,用C#的
- 关于C# 基类库和 VC++ MFC的疑问
- 请求各位推荐几本书吧。
- 如何利用反射判断一个object类型的对象是否具有索引器,并且如何提取和操作索引器内的索引和值?
如何:将 Web 浏览器功能添加到 Windows 窗体应用程序
http://msdn.microsoft.com/zh-cn/library/3s8ys666.aspx