C# 如何在窗口启动时将wpf应用程序移动到最小化托盘中?
我已使用Windows Installer创建了应用程序的安装程序 现在我想在Windows启动时启动应用程序,并将其移动到系统最小化托盘中,因为我不想在Windows启动时显示GUI(视图) 我在谷歌上搜索过,发现可以使用注册表项,但这对我来说还不够,因为我也想转到系统最小化托盘和应用程序运行 我这样做的目的是,当用户每次启动系统时,当应用程序启动时不会感到烦人 有人能回答吗?C# 如何在窗口启动时将wpf应用程序移动到最小化托盘中?,c#,wpf,windows-installer,startup,setup-project,C#,Wpf,Windows Installer,Startup,Setup Project,我已使用Windows Installer创建了应用程序的安装程序 现在我想在Windows启动时启动应用程序,并将其移动到系统最小化托盘中,因为我不想在Windows启动时显示GUI(视图) 我在谷歌上搜索过,发现可以使用注册表项,但这对我来说还不够,因为我也想转到系统最小化托盘和应用程序运行 我这样做的目的是,当用户每次启动系统时,当应用程序启动时不会感到烦人 有人能回答吗? 谢谢..在应用程序中,为FrameworkElement.Loaded事件添加事件处理程序。在该处理程序中,添加以下
谢谢..在应用程序中,为
FrameworkElement.Loaded
事件添加事件处理程序。在该处理程序中,添加以下代码:
WindowState = WindowState.Minimized;
这将使应用程序在启动时最小化
要在计算机启动时启动应用程序,您需要将程序添加到Windows计划程序中,并将其设置为在启动时运行。您可以在MSDN页面上找到更多信息。您还必须设置此属性才能将其从任务栏中删除
ShowInTaskbar= false;
也许这个答案已经晚了,但我还是想写下来帮助那些还没有找到解决方案的人 首先,您需要添加一个功能,以便在系统启动时自动启动应用程序时将其最小化
StartupUri=…
更改为Startup=“App\u Startup”
,如下所示应用程序启动是您的函数名,可以更改RegistryKey key = Registry.LocalMachine.OpenSubKey(path, true);
^_^我希望在计算机启动时最小化它的启动时间,而不是每次使用单击图标时
public partial class App : Application
{
private void App_Startup(object sender, StartupEventArgs e)
{
// Process command line args
var isAutoStart = false;
for (int i = 0; i != e.Args.Length; ++i)
{
if (e.Args[i] == "/AutoStart")
{
isAutoStart = true;
}
}
// Create main application window, starting minimized if specified
MainWindow mainWindow = new MainWindow();
if (isAutoStart)
{
mainWindow.WindowState = WindowState.Minimized;
}
mainWindow.OnAutoStart();
}
}
public void OnAutoStart()
{
if (WindowState == WindowState.Minimized)
{
//Must have this line to prevent the window start locatioon not being in center.
WindowState = WindowState.Normal;
Hide();
//Show your tray icon code below
}
else
{
Show();
}
}
private void SwitchAutoStart_OnToggled(object sender, RoutedEventArgs e)
{
const string path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
var key = Registry.CurrentUser.OpenSubKey(path, true);
if (key == null) return;
if (SwitchAutoStart.IsOn)
{
key.SetValue("Your app name", System.Reflection.Assembly.GetExecutingAssembly().Location + " /AutoStart");
}
else
{
key.DeleteValue("Your app name", false);
}
}
RegistryKey key = Registry.LocalMachine.OpenSubKey(path, true);