我有一些toolStripMenuItems作为一系列网站的有用链接,代码的粗略示例如下:
private void toolStripMenuItem1_Click(object sender, EventArgs e) { Process.Start("http://www.google.com"); } private void toolStripMenuItem2_Click(object sender, EventArgs e) { Process.Start("http://www.bing.com"); } private void toolStripMenuItem3_Click(object sender, EventArgs e) { Process.Start("https://www.duckduckgo.com"); } private void toolStripMenuItem4_Click(object sender, EventArgs e) { Process.Start("http://www.yahoo.com/"); } ...
有更优雅的方式来处理这个问题吗?
将url放在菜单项标签中并将此处理程序附加到所有这些(希望它可以正常工作)
private void toolStripMenuItemClick(object sender, EventArgs e) { Process.Start(sender.Tag.ToString()); }