在Button1下写如下代码打开网页:
Process p = new Process();\\引用using System.Diagnostics
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;\\将启动IEXPLORE的窗体设为隐藏
p.StartInfo.FileName = "IEXPLORE.EXE";\\打开IEXPLORE
p.StartInfo.Arguments = textBox1.Text;\\输入要打开的网址
p.Start();
string mytime = p.StartTime.ToString();\\定义一个变量记录刚才打开的网页的启动时间(为以后关闭它使用)
关闭指定网页,则需要根据刚才记录的标示(mytime)来关闭网页(防止关闭其他已打开的网页)
Process[] pp = Process.GetProcessesByName("iexplore");
for (int i = 0; i < pp.Length; i++)
{
if (pp[i].StartTime.ToString() == mytime)\\判断已打开的网页启动时间
{
pp[i].Kill();\\关闭网页(进程)
}
}
建议:启动和关闭之间间隔几秒时间,让网页充分打开
//停顿时间
Thread.Sleep(3000);//3000毫秒
转载于:https://www.cnblogs.com/mlccctaobao/archive/2012/06/05/2536861.html