【问题标题】:how to import a file to my application using the context menu (right Click)如何使用上下文菜单将文件导入我的应用程序(右键单击)
【发布时间】:2012-10-13 06:26:47
【问题描述】:

我希望将我的应用程序添加到-右键单击上下文菜单项中,并且我想在我右键单击文件并选择我的程序时导入文件路径

我正在使用此代码在上下文菜单中添加应用程序

private void btnAddMenu_Click(object sender, System.EventArgs e)
{
    RegistryKey regmenu = null;
    RegistryKey regcmd = null;
    try
    {
        regmenu = Registry.ClassesRoot.CreateSubKey(MenuName);
        if(regmenu != null)
            regmenu.SetValue("",this.txtName.Text);
        regcmd = Registry.ClassesRoot.CreateSubKey(Command);
        if(regcmd != null)
                regcmd.SetValue("",this.txtPath.Text);
    }
    catch(Exception ex)
    {
        MessageBox.Show(this,ex.ToString());
    }
    finally       
    {
        if(regmenu != null)
            regmenu.Close();
        if(regcmd != null)
            regcmd.Close();
    }        
}

所以任何人都知道如何将文件路径导入应用程序!

【问题讨论】:

    标签: c# shell stream contextmenu


    【解决方案1】:

    这并不难。基本上,您需要将项目添加到 Registry.ClassesRoot.CreateSubKey 注册表中。

    您可以在main(string[] args) 方法中读取参数。它将作为args 参数的内容传递。您还可以使用 Environment.GetCommandLineArgs() 方法在应用程序的其他任何位置获取该值。

    查看这些参考资料:

    1. Add a context menu to the Windows Explorer
    2. Add "Open with Notepad" to the Context Menu for All Files

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多