利用c#语言程序自动打开浏览器,源码怎么编写?
3个回答
展开全部
下面的都可以实现,我再给你发另外一种,很猛的
/// <SUMMARY>
/// Creates a COM object given it's ProgID.
/// </SUMMARY>
/// <PARAM name="sProgID">The ProgID to create</PARAM>
/// <RETURNS>The newly created object, or null on failure.</RETURNS>
public object COMCreateObject(string sProgID)
{
// We get the type using just the ProgID
Type oType = Type.GetTypeFromProgID(sProgID);
if (oType != null)
{
return Activator.CreateInstance(oType);
}
return null;
}
/// <summary>
/// Opens a new Internet Explorer window and navigates it to the URL.
/// This code is for demonstration purposes only.
/// From http://www.novicksoftware.com/TipsAndTricks/tip-csharp-open-ie-browser.htm
/// </summary>
/// <param name="sURL">URL to navigate to.</param>
/// <returns>true all the time.</returns>
public bool IEOpenOnURL(string sURL)
{
InternetExplorer oIE = (InternetExplorer)COMCreateObject
("InternetExplorer.Application");
if (oIE != null)
{
object oEmpty = String.Empty;
object oURL = sURL;
oIE.Visible = true;
oIE.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty);
}
return true;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
IEOpenOnURL(linkLabel1.Text);
}
/// <SUMMARY>
/// Creates a COM object given it's ProgID.
/// </SUMMARY>
/// <PARAM name="sProgID">The ProgID to create</PARAM>
/// <RETURNS>The newly created object, or null on failure.</RETURNS>
public object COMCreateObject(string sProgID)
{
// We get the type using just the ProgID
Type oType = Type.GetTypeFromProgID(sProgID);
if (oType != null)
{
return Activator.CreateInstance(oType);
}
return null;
}
/// <summary>
/// Opens a new Internet Explorer window and navigates it to the URL.
/// This code is for demonstration purposes only.
/// From http://www.novicksoftware.com/TipsAndTricks/tip-csharp-open-ie-browser.htm
/// </summary>
/// <param name="sURL">URL to navigate to.</param>
/// <returns>true all the time.</returns>
public bool IEOpenOnURL(string sURL)
{
InternetExplorer oIE = (InternetExplorer)COMCreateObject
("InternetExplorer.Application");
if (oIE != null)
{
object oEmpty = String.Empty;
object oURL = sURL;
oIE.Visible = true;
oIE.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty);
}
return true;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
IEOpenOnURL(linkLabel1.Text);
}
展开全部
不知道你是要winform还是web的
winform: System.Diagnostics.Process.Start("IExplore.exe", @"网址");
web: Response.Redirect("网址",true/false)
winform: System.Diagnostics.Process.Start("IExplore.exe", @"网址");
web: Response.Redirect("网址",true/false)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
System.Diagnostics.Process.Start("iexplore.exe","URL地址");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询