原文 (WinForm)文件夹状态监控,最小化到托盘,开机自启动

.            文件夾監控(監測文件夾中的文件動態):

    //MSDN上的例子
public class Watcher { public static void Main() { Run(); } [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] public static void Run() { string[] args = System.Environment.GetCommandLineArgs(); // If a directory is not specified, exit program. if (args.Length != ) { // Display the proper way to call the program. Console.WriteLine(“Usage: Watcher.exe (directory)“); return; } // Create a new FileSystemWatcher and set its properties. FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = args[]; /* Watch for changes in LastAccess and LastWrite times, and the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // Only watch text files. watcher.Filter = “*.txt“; // Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnChanged); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnRenamed); // Begin watching. watcher.EnableRaisingEvents = true; // Wait for the user to quit the program. Console.WriteLine(“Press \’q\’ to quit the sample.“); while (Console.Read() != ‘q‘) ; } // Define the event handlers. private static void OnChanged(object source, FileSystemEventArgs e) { // Specify what is done when a file is changed, created, or deleted. Console.WriteLine(“File: “ + e.FullPath + “ “ + e.ChangeType); } private static void OnRenamed(object source, RenamedEventArgs e) { // Specify what is done when a file is renamed. Console.WriteLine(“File: {} renamed to {}“, e.OldFullPath, e.FullPath); } }   . 最小化到托盤功能:
首先給主界面添加一個notifyIcon控件,給它的Icon添加一個圖標,不添加圖標的話不會在托盤顯示,然後給主界面的SizeChanged事件注冊一個方法,在方法中將主界面隱藏: void frmMain_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Hide(); } } 然後給notifyIcon的單擊或者雙擊事件添加一個方法,讓鼠標單擊或者雙擊托盤圖標的時候可以將主界面窗口還原: private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) { this.Visible = true; this.WindowState = FormWindowState.Normal; } .讓程序開機自動啟動的方法(編輯注冊表) private void chbStartup_CheckedChanged(object sender, EventArgs e) { if (this.chbStartup.Checked) { try { string startupPath = Application.ExecutablePath; RegistryKey local = Registry.LocalMachine; RegistryKey run = local.CreateSubKey(@”SOFTWARE\Microsoft\Windows\CurrentVersion\Run“); run.SetValue(“FolderWatcher“, startupPath); local.Close(); } catch (Exception ex) { MessageBox.Show(“開機啟動設置異常:“ + ex.Message); } } else { try { string startupPath = Application.ExecutablePath; RegistryKey local = Registry.LocalMachine; RegistryKey run = local.CreateSubKey(@”SOFTWARE\Microsoft\Windows\CurrentVersion\Run“); run.DeleteValue(“FolderWatcher“); local.Close(); } catch (Exception ex) { MessageBox.Show(“開機啟動設置異常:“ + ex.Message); } } }

(WinForm)文件夹状态监控,最小化到托盘,开机自启动的更多相关文章

  1. [转帖]Linux下inotify监控文件夹状态,发生变化后触发rsync同步

    Linux下inotify监控文件夹状态,发生变化后触发rsync同步 https://www.cnblogs.com/fjping0606/p/6114123.html 1.安装工具--inotif ...

  2. WinForm 之 窗口最小化到托盘及右键图标显示菜单

    Form最小化是指整个Form都缩小到任务栏上,但是窗体以Form的标题栏形式显示在任务栏上, 若是想让Form以Icon的形式显示在任务栏右下角,则需要给Form添加一个NotifyIcon控件. ...

  3. WPF实现窗口最小化到托盘,并且实现右击菜单

    原版是从网上找了一位大神的,自己只是用了一点适合自己的. 具体实现 1.首先已经确认WPF中没有实现最小化托盘的类与方法,用到了winform中的程序集 using Drawing = System. ...

  4. VC++ 最小化到托盘、恢复

    所谓的“托盘”,在Windows系统界面中,指的就是下面任务条右侧,有系统时间等等的标志的那一部分.在程序最小化或挂起时,但有不希望占据任务栏的时候,就可以把程序放到托盘区. 一.托盘编程相关函数   ...

  5. MFC窗口实现最小化到托盘 右键菜单和还原

    //.h文件 void toTray();//最小化到托盘 void DeleteTray();//删除托盘图标 afx_msg LRESULT OnShowTask(WPARAM wParam,LP ...

  6. VC最小化到托盘程序

    在实际操作电脑的过程中,我们常常可以看到一些应用程序可以最小化到桌面右下角的托盘中显示,如一些杀毒软件等开机就显示在托盘中,或是我们常用的QQ等聊天工具,都可以最小化在托盘中,如图-1. 在图-1中, ...

  7. Delphi - 利用TRzTrayIcon实现WinFrm工程最小化到托盘

    第三方RC控件的安装 浏览器搜索Delphi Rz控件下载,找到下载一个安装文件,解压后点击RC3.exe一键安装. Delphi WinFrm工程最小化到托盘 Delphi新建WinFrm工程,在主 ...

  8. 【VS开发】最小化到托盘 shell_notifyicon和NOTIFYICONDATA

    shell_notifyicon和NOTIFYICONDATA Shell_NotifyIcon函数,向任务栏的状态栏发送一个消息 函数原型 BOOL Shell_NotifIcon( DWORD d ...

  9. 将VMware虚拟机最小化到托盘栏

    版权:本文采用「署名-非商业性使用-相同方式共享 4.0 国际」知识共享许可协议进行许可.   目录 前言 将VMware最小化到托盘栏的方法 1.下载 Trayconizer 2.解压 trayco ...

随机推荐

  1. Oracle中的单引号问题

    SELECT '<a href="javascript:void(0)" onclick="openWyl('''||a.aac001 FROM ac01 a; S ...

  2. 为什么 Flask 有那么多的好评?

    著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:松鼠奥利奥链接:http://www.zhihu.com/question/28902969/answer/42530571来 ...

  3. ZOJ 3713 In 7-bit (题意不好理解,十进制、二进制、十六进制的转换问题)

    考验理解能力的时候到了 T^T Very often, especially in programming contests, we treat a sequence of non-whitespac ...

  4. 【模式识别】SVM核函数

    下面是几种经常使用的核函数表示: 线性核(Linear Kernel) 多项式核(Polynomial Kernel) 径向基核函数(Radial Basis Function) 也叫高斯核(Gaus ...

  5. UNIX网络编程——网络数据包检测

    网络数据包检测 数据包捕获(sniffer):是指在网络上进行数据收集的行为,需要通过网卡来完成. 三种访问方式: BSD Packet Filter(BPF) SVR4 Datalink Provi ...

  6. Cool Edit Pro 2.0详细教程(转)

      系统介绍一下用Cooledit pro 2.0录制自唱歌曲的一个全过程,希望对喜欢唱歌,想一展歌喉的朋友有所帮助. 录制原声 录音是所有后期制作加工的基础,这个环节出问题,是无法靠后期加工来补救的 ...

  7. 插件化—配置xml的辅助测试

    1.xml文件,xml文件在res/xml目录下 <?xml version="1.0" encoding="utf-8"?> <infos& ...

  8. 打开sa属性报错

    --如果打开sa属性报错如下:无法显示请求的对话框.属性IsLocked不可用于“登录名sa".该对象可能没有此属性,也可能是访问权限不足而无法检索 --解决办法:首先用windows登录, ...

  9. zookeeper 之znode 节点

    <pre name="code" class="html">使用 ls 命令来查看当前 ZooKeeper 中所包含的内容: [zk: 10.77. ...

  10. Myeclipse 设定文件的默认打开方式

    Myeclipse 设定文件的默认打开方式.今天下载了一个properties的中文插件,希望.property的文件能默认以这个程序打卡.说一下设置方法. Window -> Preferen ...