Click here to Skip to main content
15,793,098 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to open a picture that I have highlighted when I open a C# program that will show that picture.

The best example would be RARzip. You can highlight the files you want to add to an archive then start Rarzip and it will grab those files for when you tell it to archive them.

What I have tried:

My mind is blank just how to even attempt a search for this. Every query I have done doesn't give anything close to the answer.
Updated 12-Sep-23 9:21am
PIEBALDconsult 11-Sep-23 19:08pm    
Other than associating the file extension with your app? So your app runs when the file is opened via Explorer?
David Edwards 2022 11-Sep-23 19:22pm    
No, I want to highlight/select one or more files from file explorer. Then run a program I have written. The program pulls in the selected files and processes them as the program dictates.
PIEBALDconsult 12-Sep-23 11:31am    
How will it know which Explorer window to look at? Or all of them?

WinRAR and WinZip don't do that: You highlight the files in Explorer and then tell explorer to open WinZip or WinRAR - Explorer then adds the files to the "command line arguments" part of the application startup, and you can pick them up in your app in one of two ways.
1) If you have a Console app, then they are passed as an array of strings to to the main method:
static void Main(string[] args)
    foreach (string file in args)
For a windows GUI app, it's different:
private void FrmMain_Load(object sender, EventArgs e)
    foreach (string file in Environment.GetCommandLineArgs())
Share this answer
PIEBALDconsult 12-Sep-23 11:17am    
You mean right-click and select something like "Open with MyApp" ?
Doesn't that still require setting the app up as a file association with the Open or Edit or whatever verb ?
OriginalGriff 12-Sep-23 12:08pm    
No, you can use "open with" with unregistered extensions, and even register the extension by selecting "Always" instead of "Just once".
David Edwards 2022 12-Sep-23 12:02pm    
Oh, thank you OriginalGriff! Please, I need to get multiple files.
OriginalGriff 12-Sep-23 12:10pm    
And? What's the problem?
David Edwards 2022 12-Sep-23 12:16pm    
Ok, I seem to get an error when I try to load more than one file to an array or equivalent.

All I get it the .exe file when going to a listbox for testing. I can see why, the executable becomes the highlighted file, all other files turn off.
You're switching between a "picture" and "files".

In the case of a "picture": right click the image and copy it to the clipboard. Retrieve the image from the clipboard with your program.

Clipboard.GetImage Method (System.Windows.Forms) | Microsoft Learn[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900