0

我有一个要求,我需要在其中添加一个上下文菜单项,说“任务”,当我将鼠标指向它时,它应该显示一个弹出菜单,其中包含要使用该文件/文件夹执行的任务列表。就像您右键单击桌面上的文件夹并指向它一样,说“发送到”它会显示选项。

我能够在上下文菜单中添加“任务”,我的代码是:

RegistryKey rKey = Registry.ClassesRoot.OpenSubKey(@"Directory\shell", true);

RegistryKey newKey = rKey.CreateSubKey("Harsha");
RegistryKey newSubKey = newKey.CreateSubKey("command");
newSubKey.SetValue("", @"C:\Users\Administrator\Desktop\C Sharp\Chat Program\TestContext\TestContext\bin\Debug\TestContext.exe " + "\"" + "%1" + "\"");
newSubKey.Close();
newKey.Close();
rKey.Close();

在 TestContext.cs 中只显示我现在选择的文件/文件夹路径。此路径稍后将用于进一步处理。

static void Main(string[] arguments)
{
    string folderpath = string.Empty;
    if (arguments.Length > 0)
    {
        folderpath = arguments[0];
        MessageBox.Show(folderpath, "Test Application", MessageBoxButtons.OK, MessageBoxIcon.None);

    }
    else
    {
        MessageBox.Show("You need to select a folder to continue.", "Test Application", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

现在,我想将带有任务选项的子菜单添加到“任务”。当我选择一个选项时,我怎么知道选择了哪个选项?请问我可以知道怎么做吗?在此先感谢您的帮助。

4

0 回答 0