用C#编写的记事本,将它设为文本的默认启动程序后,双击文本(*.txt)后将文本内容显示出来,应该怎么做?请多指教!!

解决方案 »

  1.   

    写注册表 。
    Microsoft.Win32.RegexKey.
      

  2.   

    google “注册表 文件关联”
      

  3.   

    一个是注册表关联,这个上面说了,还有一个就是在 void Main(string[] Args)中通过 Args获取双击传入的文件名:
    MessageBox.Show(string.Join(",", Args)); //你可以试试看,这里可以获得你打开了什么文件
      

  4.   

     #region 写入程序相关
          private void WriteApp()
             {
                 //设置程序打开路径
                 string path = "\"C:\\Users\\Administrator\\Desktop\\Test\\TestWinForm\\bin\\Debug\\TestWinForm.exe\"";
                 RegistryKey root = Registry.ClassesRoot;
                 RegistryKey f1 = root.CreateSubKey("Form1");
                //设置注册表程序打开的项与值,其中SetValue("", path)代表设置默认值
                 f1.CreateSubKey("shell").CreateSubKey("Open").CreateSubKey("Command").SetValue("", path);
     
                 //设置程序图标
                string ico = "\"C:\\Users\\Administrator\\Desktop\\u7_original.ico\"";
                 f1.CreateSubKey("DefaultIcon").SetValue("", ico);
            }
             #endregion
     
             #region 写关联文件
             private void WriteRelate()
             {
                 RegistryKey root = Registry.ClassesRoot;
                 //设置打开程序
                 root.CreateSubKey(".cws").CreateSubKey("OpenWithProgids").SetValue("Form1","");
             }
             #endregion把注册表的记事本路径改了就OK ; 
      

  5.   

    在注册表里设置文件关联,
    把 txt文件打开的默认程序设为你的程序
      

  6.   

    shell ContextMenu 注册文件右键
    http://topic.csdn.net/u/20100830/16/04688fb1-62e9-427f-839a-e3aa4e1232cb.html
      

  7.   

    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\
    OpenWithProgids
    OpenWithList这个下面