程序生成的自定義文件,比如后綴是.test
這種文件怎么直接啟動(dòng)打開程序,并打開本文件呢
1、雙擊打開
2、自定義的文件,有圖標(biāo)顯示
3、自定義的文件,點(diǎn)擊右鍵有相應(yīng)的屬性
后臺(tái)代碼:(如何在注冊(cè)表中修改信息)
  //工具啟動(dòng)路徑  string toolPath = System.Windows.Forms.Application.StartupPath + "//郵件小工具.exe";  string extension = SptdConst.FileExtension;  string fileType = "Email File";  string fileContent = "text/plain";  //獲取信息  Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension);  if (registryKey != null && registryKey.OpenSubKey("shell") != null && registryKey.OpenSubKey("shell").OpenSubKey("open") != null &&    registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command") != null)  {    var varSub = registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command");    var varValue = varSub.GetValue("");    if (Object.Equals(varValue, toolPath + " %1"))    {      return;    }  }  //刪除  Microsoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree(extension, false);  //文件注冊(cè)  registryKey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension);  registryKey.SetValue("文件類型", fileType);  registryKey.SetValue("Content Type", fileContent);  //設(shè)置默認(rèn)圖標(biāo)  Microsoft.Win32.RegistryKey iconKey = registryKey.CreateSubKey("DefaultIcon");  iconKey.SetValue("", System.Windows.Forms.Application.StartupPath + "//logo.ico");  //設(shè)置默認(rèn)打開程序路徑  registryKey = registryKey.CreateSubKey("shell//open//command");  registryKey.SetValue("", toolPath + " %1");  //關(guān)閉  registryKey.Close();在修改了注冊(cè)表信息后,雙擊文件是啟動(dòng)了軟件,之后怎么在代碼中操作?
//雙擊啟動(dòng)打開 //如果原有路徑中存在空格,則會(huì)分解成多個(gè)元素if (e.Args.Length > 0){   string filePath = String.Join(" ", e.Args.ToArray());   FileInfo file = new FileInfo(filePath);   if (file.Exists)    {      EmailToolConst.DoubleClickSptdFilePath = file.FullName;    } }	然后可以在主程序loaded方法中,判斷DoubleClickSptdFilePath 是否有值,如果有,則獲取路徑下的文件,繼續(xù)操作。
以上就是小編為大家整理的C#設(shè)置自定義文件圖標(biāo)實(shí)現(xiàn)雙擊啟動(dòng)的全部?jī)?nèi)容,希望這篇文章的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能有一定的幫助,如果有疑問可以留言交流。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注