Windows窗体应用程序 - 标签中的URL [英] Windows Forms Application - URL from label
本文介绍了Windows窗体应用程序 - 标签中的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将标签中的文字添加到 WebBrowser 的 URL 。
ToolBox - >标签
工具箱 - > Web浏览器
我想这样做:
How to add a text from label to the URL of a WebBrowser.
ToolBox -> Label
ToolBox -> WebBrowser
I wanna do this:
string URL_ST = "";
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
URL_ST = textBox1.Text;
}
///How to set the webBrowser URL to URL_ST
///PLS HELP
我需要这个,因为我会做一个互联网浏览器。
我不是只做这个!
帮我! PLS!
不太懂英语:)
I need this because I''ll do an internet browser.
I didn''t do only this!
Help me! PLS!
Do not know very good English :)
推荐答案
试试这个:
Try this:
Process.Start("http://google.com");
祝你好运!
Good luck!
其中任何一个都应该工作
Either of these should work
WebBrowser1.Url = New Uri("http:\\www.example.com\" + URL_ST);
或
OR
WebBrowser1.Navigate("www.example.com\" + URL_ST);
所以,如果你有 URL_ST = default.aspx
,然后新的网址将是 http:\\www.example.com \ default.aspx
So, if you have URL_ST = default.aspx
, then new Url will be http:\\www.example.com\default.aspx
实际上我用Navigate解决了它。 TNX到Tadit Dash。
他说我可以用Navigate做到。但是没有功能导航。
所以这里是代码:
Actually I solved it with the Navigate. TNX to Tadit Dash.
He said I can do it with Navigate. But there isn''t a function Navigate.
So here is the code:
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;
}
}
这篇关于Windows窗体应用程序 - 标签中的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文