Question:
Visual Basic.Net Programming Help?!?
sbraidley
2007-04-16 14:27:51 UTC
Now this is quite advanced but I hope someone out there can help because Ive just finished work on a Notepad like program but I want to be able right click say a html file and click open with> My program now I have added it to the list but when it luanches the program it dosen't load the document I wish so how can I make it open the document via the open with link?
Im guessing I need to insert code into the Form1_Load area which checks if its been opened from that menu but I need code or info on how to do this so please give a link or code that has comments.
Thanks
Please ensure its Visual Basic.Net
Three answers:
Paul R
2007-04-16 15:51:44 UTC
If I understand your question correctly, what you want is to be able to right-click on a file on the desktop or in a folder window, and in the right-click menu, have an open option to open it with your program. This is not a visual Basic.net issue, but an issue with Explorer (and with the registry).



The easy way to do this is from any directory, click on View, click on "Folder Options" in the new window, then click on the file types tab.



Find the extension and you can add your option there.



If you need a file to set this up for a program you're running to be able to do this, you need to create a registry entry. Here's how you do that.



What is required is that you need to have the file type registered for your program. First, the file extension has to be registered. Let's make up a file extension type, say, .question, so that any time a file with the extension ".question" is double-clicked upon, it will be opened by a program. Or you can have other right-click options, too.



There needs to be a key in the registry like this:

HKEY_CLASSES_ROOT\.question

the (default) value for this key is the information about what is to be done with files of type .question. Let's call the value "QuestionFile".



There is then needed a registry key to tie the link to that entry:

HKEY_CLASSES_ROOT\QuestionFile

the (default) value is the description, let's call the value "Miscellaneous Questions".



You need to be able to access it from the shell by clicking on it, so you need a subkey

HKEY_CLASSES_ROOT\QuestionFile\shell

the (default) value is what is the command to execute for double click, the "default" action. Now, if it already has an action defined, there will be a sub folder with that name. Let's say that there will be three options for files of .quiestion, to Ask, to Answer, and to Comment; Answer will be the default, but when you right click on a .questions file, there will be a pop-up menu and you can use Alt-A to Ask, Alt-W to answer, and Alt-C to comment. You'll run a different program for each.



In the window below is an example of the keys and values set up in the registry as a result.



This only needs to be set up once, now, if you want this set up for a program being installed places, you need to have your installer set up the registry keys. If you copy the file below in notepad, save it as a file ending in .REG, then right-click on it, it will install a registry entry to provide this feature, then you can look at it and see how it works.



What's most important in these is the %1 field, which is the name of the file which has been clicked upon; that is then passed to the program being executed. In VB you can get the file name passed as a parameter through the Command() function.
?
2016-05-17 08:22:10 UTC
I had been programming industrial tools-machines and a line of robots long ago, but I never used C, C++, Visual C, whatsoever. As long as I know these are languages used to realise programmes as an interface between the machine language (ASCII codes) & the user of that specifique machine (the user of the computer which puts in motion those robots by the means of a programme). But "robots programming" is much more simple than realising a specific programme in such a language. O.K. it depends on what exactly you may preffere to do. And it's much more easy to work into an office than into the production lines where it's much more animation though, and great satisfaction by the results of the work. It's building something which you can TOUCH and have it done under your own eyes, which is greater than the programme realisation. You can be just a technician or a technological engineer, you just have to know the process in which those robots shall work, and you have to become familiar with some concordance you must take and be aware of between the machines reference systems and the programe in itself, and THIS is the most important in order to have the programme you've realised in the proper function. Else, the programme is of no use if your refference systems aren't well choose on the machine/robot. BUT you must talk about the realisation of a specific programme to be used by the proccessor of a robot which is slightly different from "robots programming" in itself.
Paxo
2007-04-17 02:04:06 UTC
Dude - what you are looking for hearkens back to the dark ages before Windows! In those days, if you wanted ProgramX to open FileY, you would type into the command line "ProgramX FileY" with FileY being the command line argument.



I did a similar thing one of my apps:



Dim strCommandLineArgs() As String = Environment.GetCommandLineArgs

Dim strCommandLineArg As String

If strCommandLineArgs.GetUpperBound(0) > 0 Then

strCommandLineArg = strCommandLineArgs(1)

Try

Dim objReader As StreamReader = _

New StreamReader(strCommandLineArg)

txtTextBox.Text = objReader.ReadToEnd()

objReader.Close()

Catch



End Try

End If



That loads a text file into txtTextBox. You'll need to amend it if you're loading a different type of file.



Good luck :)



PS sorry about the formatting of the answer - having issues with this webpage shortening my lines - the If clause should be Get Upper Bound (0) with no spaces.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...