Custom files generated by the program, such as the suffix. Test
How does this file start to open the program directly and open the file?
1. Double-click to open
2. custom files with icon display
3. Customize the file, right click to have the corresponding property
Background code: (How to modify information in the registry)
//Tool Startup Path stringToolpath = System.Windows.Forms.Application.StartupPath +"\ \ Mail gadget. exe"; stringExtension =sptdconst.fileextension; stringFileType ="Email File"; stringFilecontent ="Text/plain"; //Get informationMicrosoft.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) { varVarsub = Registrykey.opensubkey ("Shell"). OpenSubKey ("Open"). OpenSubKey ("Command"); varVarvalue = Varsub.getvalue (""); if(Object.Equals (varvalue, Toolpath +"%1")) { return; } } //DeleteMicrosoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree (Extension,false); //File RegistrationRegistryKey =Microsoft.Win32.Registry.ClassesRoot.CreateSubKey (extension); RegistryKey.SetValue ("File Type", FileType); RegistryKey.SetValue ("Content Type", filecontent); //Set default iconMicrosoft.Win32.RegistryKey Iconkey = Registrykey.createsubkey ("DefaultIcon"); Iconkey.setvalue ("", System.Windows.Forms.Application.StartupPath +"\\logo.ico"); //Set default open program pathRegistryKey = Registrykey.createsubkey ("Shell\\open\\command"); RegistryKey.SetValue ("", Toolpath +"%1"); //CloseRegistrykey.close ();
After you have modified the registry information, double-click the file to start the software, and then how to operate in the code?
// If a space exists in the original path, it will be decomposed into multiple elements if0) { string FilePath = String.Join ("", E.args.toarray ()); New FileInfo (FilePath); if (file. Exists) { = file. FullName; } }
You can then determine whether the Doubleclicksptdfilepath has a value in the main program loaded method, and if so, get the file under the path and proceed.
C # customization file icon Double-click Start (Modify registry)