WinForm 打开IE 控制各种IE属性
staticvoid Main(string[] args)
{
GenerateHTML();
ProcessStartInfo startInfo =new ProcessStartInfo("IExplore.exe");
startInfo.Arguments = Environment.CurrentDirectory +"\\index.html";
Process process1 =new Process();
process1.StartInfo = startInfo;
process1.Start();
}
static void GenerateHTML()
{
string fileName = "index.html";
string url = "http://www.xxxxxxx.com";
StringBuilder sb = new StringBuilder();
sb.AppendLine("<html>");
sb.AppendLine("<head>");
sb.AppendLine("<script lanuage='javascript'>");
sb.AppendLine("function init() {");
sb.AppendFormat("window.open('{0}',null,'height=200,width=400,status=yes,toolbar=no,menubar=no,location=no');\n", url);
sb.AppendLine("window.close();");
sb.AppendLine("}");
sb.AppendLine("</script>");
sb.AppendLine("</head>");
sb.AppendLine("<body onload='init()'>");
sb.AppendLine("</body>");
sb.AppendLine("</html>");
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(sb.ToString());
sw.Flush();
}
}
}
int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;//显示器的宽度
int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;//显示器高度
string fileName = "openIE.vbs";
string url = "http://www.baidu.com";
StringBuilder sb = new StringBuilder();
sb.AppendLine("Set ie= createobject(\"InternetExplorer.Application\")");
sb.AppendLine(string.Format("ie.left={0}",width/2-200));
sb.AppendLine(string.Format("ie.top={0}",height/2-150));
sb.AppendLine("ie.width=400");
sb.AppendLine("ie.height=300");
sb.AppendLine("ie.menubar=0");
sb.AppendLine("ie.addressbar=0");
sb.AppendLine("ie.toolbar=0");
sb.AppendLine("ie.statusbar=0");
sb.AppendLine("ie.resizable=0");
sb.AppendLine("ie.visible=1");
sb.AppendFormat("ie.navigate(\"{0}\")", url);
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(sb.ToString());
sw.Flush();
}
}
}