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("监听程序,不可关闭!"); }