在C# 中写了个Winform程序,需要打开IE浏览器,现在想控制IE的窗口大小并屏蔽工具栏、地址栏,也就是只要标题栏的那种。
我的代码是用:
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.Arguments = "www.microsoft.com";
Process process1=new Process ();
process1.StartInfo =startInfo;
process1.Start();
他是要设参数吗???哪些参数??
有没有别的方法??
我的代码是用:
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.Arguments = "www.microsoft.com";
Process process1=new Process ();
process1.StartInfo =startInfo;
process1.Start();
他是要设参数吗???哪些参数??
有没有别的方法??
1. 获取当前IE Shell窗口
2. 修改窗口属性参考代码: http://www.codeproject.com/KB/cs/automatinginternetexplore.aspx
Set ie= createobject("InternetExplorer.Application")ie.left=-5
ie.top=-25
ie.height=900
ie.width=1035
ie.menubar=0
ie.addressbar=0
ie.toolbar=0
ie.statusbar=0
ie.resizable=0
ie.visible=1
ie.navigate("http://www.sina.com.cn")呵呵,程序大多相通,谁说玩asp的就一定比不过net
static void 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.microsoft.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();
}
}
}
你的方法虽然可以实现上述设想,但是存在一定的问题:
1、在window.close()时总要询问是否关闭窗口
2、在XP中运行JS,会出现“是否运行脚本”的提示
以上两条影响到了用户的操作有没有更好的方法?就是能够直接打开,并指定URL,IE窗口还能定制?
{
public Type tIE; public object oIE; public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
object[] oParameter = new object[1]; tIE = Type.GetTypeFromProgID("InternetExplorer.Application"); oIE = Activator.CreateInstance(tIE); oParameter[0] = (bool)true; tIE.InvokeMember("Visible", BindingFlags.SetProperty, null, oIE, oParameter); oParameter[0] = (string)"http://www.google.com"; tIE.InvokeMember("Navigate2", BindingFlags.InvokeMethod, null, oIE, oParameter);
}
}
}呵呵,跟你说过了程序大体相通,既然asp可以使用com,为啥net不能使用com呢?
我再修改一下,结合楼上的VBS:
static void Main(string[] args)
{
GenerateVBS();
ProcessStartInfo startInfo = new ProcessStartInfo(Environment.CurrentDirectory + "\\openIE.vbs");
//startInfo.Arguments = Environment.CurrentDirectory + "\\openIE.vbs";
Process process1 = new Process();
process1.StartInfo = startInfo;
process1.Start();
} static void GenerateVBS()
{
string fileName = "openIE.vbs";
string url = "http://www.microsoft.com";
StringBuilder sb = new StringBuilder();
sb.AppendLine("Set ie= createobject(\"InternetExplorer.Application\")");
sb.AppendLine("ie.left=0");
sb.AppendLine("ie.top=0");
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();
}
}
}
怎么看你们都写了那么多啊?