您的位置:首页 > 其它

WPF 应用程序开机自启动及窗体关闭按钮作用失效的解决办法

2013-03-14 11:15 676 查看
1、写的一个WPF应用程序,如何开机自启动?
        public void AutoOpen()
{
//获取程序执行路径..
string starupPath = AppDomain.CurrentDomain.BaseDirectory + "HSFJQAlarm.exe";
//class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装.
RegistryKey loca = Registry.LocalMachine;
RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
try
{
//SetValue:存储值的名称
run.SetValue("david", starupPath);
loca.Close();
}
catch (Exception ex)
{
MessageBox.Show("错误消息为:"+ex.Message);
}
}
 
 
2、WPF窗体的关闭按钮如何不起作用?
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
MessageBox.Show("监听程序,不可关闭!");
}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐