program as default

Yoda

Member
Joined
May 8, 2010
Messages
5
Programming Experience
Beginner
hey
i want to write a program and set it as default to open .txt files
so when i double click on a text file that it opens in that program and displays the text into a RichTextBox

my question is how do i display the text in the RichTextBox after opening the program through a double click on a text file?

Yoda
 
When you double-click a data file in Windows Explorer, the default app is executed and the data file path is passed as a commandline argument. For instance, if you double-click a text file it's just like opening a command prompt window and typing:
VB.NET:
notepad "file path here"
In a .NET app there are two usual ways to access those commandline arguments:

1. In the Startup event of the application you can get the commandline arguments from the 'e' parameter before any forms have been created.

2. Call Environment.GetCommandLineArgs anywhere in code, e.g. the Load event handler of your main form.
 
i use command prompt sometimes and know how to use it so i understand what you mean with that but i tried it with the e on form load

VB.NET:
Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
but e just gives me e.Empty / e.Equals / e.GetHashCode / e.GetType / e.ReferenceEquals and e.ToString as valid options

i also tried Environment.GetCommandLineArgs
with this code
VB.NET:
TextBox1.Text = Environment.GetCommandLineArgs.ToString
but that just shows me "System.String[]" not the filepath

could you please give an example

btw. im using Microsoft Visual Basic 2008 Express Edition
Thanks
 
First up, I did not say that you can use the 'e' parameter in the Load event handler of a form. I mention them in entirely different contexts.

As for using Environment.GetCommandLineArgs, I didn't suggest that you should call ToString on it. Did you search for any existing examples? Did you read the MSDN documentation? There are lots of sources of information you can try before you have to have someone else do it for you. Look first, ask questions later.
 
ok thanks found what i wanted

Excellent. Trust me, you'll learn far more by seeking out information for yourself than having others hand it to you. We're always here if you can't find what you're looking for but you should always look first. The more you look for information the better you get at finding it, so you can start to solve more of your own problems faster. You'll also happen upon all sorts of useful information that you weren't looking for.
 
ya i looked a lot before i asked but i couldnt find the right thing
you gave me the right hint to find it :D

i normally solve all the problems on my own and i google a lot of the stuff im looking for but here i couldnt find anything until you told me
Environment.GetCommandLineArgs

thanks
 
Back
Top