通过双击文件启动我的程序时,如何获取文件名? [英] When my program is launched by double clicking on a file how can I get the file name?
问题描述
我已经将我的vb.net程序与文件扩展名相关联,这样如果我的程序使用的其中一个文件被双击,它将打开该程序。
我需要知道被点击的文件的名称。
我确信有一种非常简单的方法可以做到这一点,我只是不知道它是什么。如果有人能告诉我,我将不胜感激。
谢谢
Hi,
I've associated my vb.net program with a file extension so that if one of the files my program uses is double clicked it will open the program.
I need to know the name of the file that was clicked.
I'm sure there's a really easy way to do this, I just don't know what it is. I would appreciate it if someone could tell me.
Thanks
推荐答案
有一大堆My.Application
和My.Application.Info
下的内容。你应该能够在那里找到它,但是在我的脑海中,我不记得究竟在哪里。
There is a whole bunch of stuff underMy.Application
andMy.Application.Info
. You should be able to find it there, but off the top of my head, I cannot remember exactly where.
Homero Rivera使用了一个C#示例,但原则仍然存在......你可以使用参数(参数)声明您的Main函数,例如
Homero Rivera used a C# example but the principle still stands...You can declare your Main function with arguments (parameters) e.g.
Module Module1
Sub Main(ByVal CmdArgs() As String)
For Each s As String In CmdArgs
Console.WriteLine(s)
Next
Console.ReadKey()
End Sub
End Module
如果你声明没有参数的Main函数,你仍然可以按照Peter_in_2780提供的链接访问命令行参数,例如
If you declare the Main function without arguments then you can still access the command line arguments as per the link provided by Peter_in_2780 e.g.
Module Module1
Sub Main()
For Each t As String In My.Application.CommandLineArgs
Console.WriteLine(t)
Next
Console.ReadKey()
End Sub
End Module
除了像你所做的那样建立文件扩展名关联之外,你还可以将文件拖放到可执行文件中相同的效果,或将您的可执行文件复制到(例如)C:\ Users \Default \ AppData \Roaming\Microsoft \Windows \ SendTo,这样当您右键单击文件时它将出现在上下文菜单中在资源管理器中
In addition to making a file extension association as you have done, you can also drop files onto the executable for the same effect, or copy your executable into (e.g.) C:\Users\Default\AppData\Roaming\Microsoft\Windows\SendTo so it will appear in the context menu when you right-click on a file in Explorer
这篇关于通过双击文件启动我的程序时,如何获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!