这看起来确实很难破解。感谢@keyboardP 的建议,因为它是一个可行的替代方案,但我最终创建了一个特殊的方法和枚举(因为当我得到答案或 cmets 时 SO 没有给我发电子邮件......我需要检查我的偏好...... ):
internal static void ShowTip(Int32 timeout, String tipTitle, String tipText, ToolTipIcon tipIcon = ToolTipIcon.None, ShowTipAction tipAction = ShowTipAction.STA_Shown_WriteReg, String linkToOpen = "")
{
if ((tipAction & ShowTipAction.STA_Nothing) == 0) // if STA_Nothing has not been passed
{
if ((tipAction & ShowTipAction.STA_Clicked_Nothing) == 0 && ((tipAction & ShowTipAction.STA_Clicked_OpenLink) > 0 || (tipAction & ShowTipAction.STA_Clicked_WriteReg) > 0))
trayIcon.BalloonTipClicked += (s, e) => // if STA_Clicked_Nothing has not been passed and either STA_Clicked_OpenLink or STA_Clicked_WriteReg has been passed
{ // when this balloon tip is clicked
if ((tipAction & ShowTipAction.STA_Clicked_OpenLink) > 0) // open passed link
MethodorProcessToLaunchSite(linktoOpen);
if ((tipAction & ShowTipAction.STA_Clicked_WriteReg) > 0) // write notification indicator to registry
RegWriteMethod;
};
if ((tipAction & ShowTipAction.STA_Closed_Nothing) == 0 && (tipAction & ShowTipAction.STA_Closed_WriteReg) > 0) // if STA_Closed_Nothing has not been passed and STA_Closed_WriteReg has been passed
trayIcon.BalloonTipClosed += (s, e) => { RegWriteMethod; }; // when this balloon tip is closed, write notification indicator to registry
if ((tipAction & ShowTipAction.STA_Shown_Nothing) == 0 && (tipAction & ShowTipAction.STA_Shown_WriteReg) > 0) // if STA_Shown_Nothing has not been passed and STA_Shown_WriteReg has been passed
trayIcon.BalloonTipShown += (s, e) => { RegWriteMethod; }; // when this balloon tip is shown, write notification indicator to registry
}
// Show the balloon tip
trayIcon.ShowBalloonTip(timeout, tipTitle, tipText, tipIcon);
}
... 和枚举:
[Flags]
internal enum ShowTipAction
{
STA_Nothing = 1,
STA_Clicked_Nothing = 2,
STA_Clicked_OpenLink = 4,
STA_Clicked_WriteReg = 8,
STA_Closed_Nothing = 16,
STA_Closed_WriteReg = 32,
STA_Shown_Nothing = 64,
STA_Shown_WriteReg = 128
}
在 lambdas 和 enum 之间,我可以根据自己的喜好使其具有可扩展性。
我知道这并不是最漂亮的解决方案,但它确实有效;出奇的好!