using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace openUrl
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
string add = "";
if (!(txtUrl.Text.Trim().StartsWith("http://")))
{
add = "http://" + txtUrl.Text.Trim();
txtUrl.Text = add;
}
webBrowser1.Url = new Uri(add);
}
}
}
此博客展示了一段C#代码,用于实现打开URL的功能。代码中定义了一个窗体类,在按钮点击事件里,会对输入的URL进行处理,若不以'http://'开头则添加该前缀,最后使用WebBrowser控件打开URL。
949

被折叠的 条评论
为什么被折叠?



