[英]Hyperlink an Email Address using LinkLabel in C#
我做了一个关于框的意思是允许用户点击超链接电子邮件地址,这将把他们带到Microsoft Outlook,以便能够向电子邮件地址发送电子邮件,但我不知道如何将其链接到Outlook并允许用户单击链接以执行此操作
你不是说你是在WinForms中使用Win或WebForms ......我认为你需要为click事件创建一个事件处理程序。 在里面你可以输入以下内容来启动默认邮件应用程序:
System.Diagnostics.Process.Start("mailto:youremail@xx.com");
检查这个SO线程:
基本上,click事件将是这样的:
private void linkLabel1_LinkClicked(object sender,System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "mailto:someone@somewhere.com?subject=hello&body=love my body";
proc.Start();
}
在表单的构造函数中添加这样的LinkLabel
:
linkLabel1.Links.Add(new LinkLabel.Link(0, linkLabel1.Text.Length, "mailto:bob@someaddress.com"));
然后,在LinkLabel
的点击处理程序中:
linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited = true;
string target = e.Link.LinkData as string;
System.Diagnostics.Process.Start(target);
<a href="mailto:bob@someaddress.com"></a>.
如果在用户的机器上安装了outlook,它将使用它。
编辑:oops只是注意到你想要Winforms而不是web。
对于winforms,在click事件处理程序中使用System.Diagnositcs.Process.Start(outlook.exe /c ipm.note /m bob@someadress.com)
。
在表单上放置一个链接标签。
双击链接标签以创建on click处理程序,然后将系统进程调用放入其中,如下所示:
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabel1.LinkVisited = true;
System.Diagnostics.Process.Start("mailto:info@cybersprocket.com");
}
这将触发用户在其Windows框中配置的默认电子邮件应用程序。
将mailto:替换为HTTP引用,以在其默认浏览器中打开网页:
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabel1.LinkVisited = true;
System.Diagnostics.Process.Start("http://www.cybersprocket.com");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.