做了个小程序,带有NotifyIcon托盘图标并且设置了开机启动.
测试发现当使用NotifyIcon时开机启动失效,去掉NotifyIcon时能开机能正常启动
NotifyIcon代码
System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.Text = "^(* ̄(oo) ̄)^";
notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
notifyIcon.Visible = true;
System.Windows.Forms.MenuItem editText = new System.Windows.Forms.MenuItem("编辑");
editText.Click += new EventHandler(EditText);
System.Windows.Forms.MenuItem setup = new System.Windows.Forms.MenuItem("设置");
setup.Click += new EventHandler(SSetUp);
System.Windows.Forms.MenuItem close = new System.Windows.Forms.MenuItem("退出");
close.Click += new EventHandler(CloseWindow);
System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { editText, setup, close };
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
开机启动代码
//开机启动
if (StartRun.IsChecked == true)
{
RegistryKey RKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
var Notes = RKey.GetValue("Notes");
if (Notes == null)
{
var a = this.GetType().Assembly.Location;
RKey.SetValue("Notes", this.GetType().Assembly.Location);
}
RKey.Close();
}
else
{
RegistryKey RKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
//RKey.DeleteSubKey("Notes", false);
RKey.DeleteValue("Notes", false);
RKey.Close();
}
新人第一次发,没有分,不好意思!
有知道问题的还请告知xiao