你可以这样来做:
在主法:
if ((args.Length > 0 && args[0].ToLower() == "minimized") ||
(AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0 &&
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0] == "minimized"))//ClickOnce arguments
{
//My code to start minimized. My system tray is always visible
main.WindowState = FormWindowState.Minimized;
main.Hide();
main.ShowInTaskbar = false;
}
else {
//Code to start normally
main.WindowState = FormWindowState.Normal;
main.ShowInTaskbar = true;
main.Show();
}
然后,你可以传递参数“最小化”与的ClickOnce应用程序来启动它最小化。
要开始我的ClickOnce应用程序自动,我做出这样的快捷方式:
CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + @"\LVH Tools\MyMiniTools.appref-ms", Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\MyMiniTools", "minimized")
“MyMiniTools”是应用程序的名称,和“左心室肥厚工具”是出版商的名称。
CreateShortcut:
public void CreateShortcut(string destinationPath, string shortcutPath, string arguments = "")
{
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
shortcutPath = Path.ChangeExtension(shortcutPath, "lnk");
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);
shortcut.TargetPath = destinationPath;
shortcut.IconLocation = destinationPath;
shortcut.Arguments = arguments;
shortcut.Description = Path.GetFileNameWithoutExtension(destinationPath);
shortcut.Save();
}
的另一种方法,以使自动启动使用ClickOnce在ClickOnce application autostart and clean uninstall or the way to customize ClickOnce installation进行说明。
这就是我正在做的计划 - 无法找到更好的方法! (如果你这样做,记得在每次升级后更新帮助程序的快捷方式)。 感谢您确认这是发生了什么! – 2009-07-18 10:28:32