qq_35108560 2019-01-24 16:09
浏览 376

WPF中NotifyIcon与开机启动冲突?

做了个小程序,带有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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab有关常微分方程的问题求解决
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable