|
-
Mar 3rd, 2013, 11:15 PM
#1
Thread Starter
New Member
Notepad Program - Open TXT File by Double Clicking
Hey,
I have created a vb 2008 express program that I call TruPad which is a notepad program similar to the one that came with windows. I have made it so I can open a txt file inside the program through a button, but I want to make my program the default program that opens when a user double clicks a .txt file in explorer. When they double click the .txt file in explorer, my program should open and display the data in the .txt file that was clicked, in the rich text box.
Can't figure that out.
Please help? Thanks
Brian
-
Mar 4th, 2013, 12:02 AM
#2
Re: Notepad Program - Open TXT File by Double Clicking
Only part of that relates to the application itself. You have to design your application such that it can receive a file path as a commandline argument. In this case, you'd probably call Environment.GetCommandlineArgs in the Load event handler of the main form. It's up to you whether you want to restrict the user to opening one file at a time or allowing multiple but you would have to check that each argument is a valid file path and then open that file just as you would if the user clicked your Button. You can then test that that is working properly by opening the Debug page of the project properties and inserting a file path (testing both valid and invalid for correct behaviour) into the commandline arguments field.
The other part is getting Windows to execute your app and pass the file as a commandline argument when it's double-clicked in Windows Explorer. That's configured in Windows itself. In Windows 7 you open the Default Programs applet from the Control Panel and click the 'Associate a file type...' link. You then select the file extension you want to open and the application you want to open it with.
Unless you use an installer or add some code to edit the Registry in your app, each user will have to do that manually. Pretty much any automated installer will be able to do it automatically. For instance, if you're using ClickOnce, use the File Associations item in the Publish Options dialogue.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|