admin管理员组文章数量:1303673
Add Windows context menu as "Merge PDF" when selecting multiple PDF files. After the addition, display only if multiple PDF files are selected. When the user clicks on the "Merge PDF", starts as a single instance of the application and loads all selected pdf on the listview.
Add Windows context menu as "Open PDF" when selecting single PDF files. After the addition, display only if single PDF files are selected. When the user clicks on the "Merge PDF", starts as a single instance of the application and displays a file name in the message box.
Actually, the I wrote original code in vb. As we know C# is used more widely than vb for that reason, I just made a conversion into the C# for easy understanding for C# developers.
I trying and add it to the Windows context menu.
private void cmdRegisterContextMenu_Click(object sender, EventArgs e)
{
// Registry path for PDF files
string pdfKeyPath = @"SystemFileAssociations\.pdf\Shell";
string openKeyPath = pdfKeyPath + @"\Open PDF";
string mergeKeyPath = pdfKeyPath + @"\Merge PDF";
// Path to your application executable
string appPath = "\"" + Application.ExecutablePath + "\"";
// Register "Open PDF" for single file selection
using (RegistryKey openKey = Registry.ClassesRoot.CreateSubKey(openKeyPath))
{
openKey.SetValue("", "Open PDF");
openKey.SetValue("Icon", appPath);
}
using (RegistryKey openCommandKey = Registry.ClassesRoot.CreateSubKey(openKeyPath + @"\Command"))
{
openCommandKey.SetValue("", appPath + " \"%1\"");
}
// Register "Merge PDF" for multiple file selection
using (RegistryKey mergeKey = Registry.ClassesRoot.CreateSubKey(mergeKeyPath))
{
mergeKey.SetValue("", "Merge PDF");
mergeKey.SetValue("App", appPath);
mergeKey.SetValue("Icon", @"E:\My Software\WindowsApp29\Project\Extra\graph_chart.ico");
}
using (RegistryKey mergeCommandKey = Registry.ClassesRoot.CreateSubKey(mergeKeyPath + @"\Command"))
{
mergeCommandKey.SetValue("", appPath + " \"%*\"");
}
MessageBox.Show("Context menu entries registered successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void ContextMenu_Load(object sender, EventArgs e)
{
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1)
{
var pdfFiles = new List<string>();
for (int i = 1, loopTo = args.Length - 1; i <= loopTo; i++)
pdfFiles.Add(args[i]);
LoadPDFsIntoListView(pdfFiles);
}
}
public void LoadPDFsIntoListView(List<string> pdfFiles)
{
foreach (string pdfFile in pdfFiles)
{
var item = new ListViewItem(pdfFile);
ListView1.Items.Add(item);
}
}
But, the few required and still serching the solution.
"Merge PDF" multiple files not working
mergeCommandKey.SetValue("", appPath + " \"%*\"");
"Merge PDF" only dispaly when multiple pdf files are selected.
"Merge PDF" start with single instance.
"Open PDF" only dispaly when single pdf file is selected.
"Open PDF" start with single instance.
版权声明:本文标题:c# - Integration in Windows Shell context menu for multiple files with selection dispaly of menu - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741771958a2396806.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论