vb.net – StartupNextInstance事件中的Environment.GetCommandL
发布时间:2020-12-17 07:14:04 所属栏目:百科 来源:网络整理
导读:我在尝试让Environment.GetCommandLineArgs()在StartupNextInstance事件中以它在表单的Load事件中的方式工作时遇到了麻烦.下面的代码检查应用程序是否有命令行参数,并将文件路径发送到FileOpen()函数,该函数基本上通过将文件名放入其参数来打开程序中的文件.
我在尝试让Environment.GetCommandLineArgs()在StartupNextInstance事件中以它在表单的Load事件中的方式工作时遇到了麻烦.下面的代码检查应用程序是否有命令行参数,并将文件路径发送到FileOpen()函数,该函数基本上通过将文件名放入其参数来打开程序中的文件.
If Environment.GetCommandLineArgs().Length > 1 Then FileOpen(Environment.GetCommandLineArgs(1)) 上面的代码在Load事件中完美运行,尽管它在StartupNextInstance事件中不起作用.我还尝试了下面的代码来获取命令行args的文件路径: Private Sub MyApplication_StartupNextInstance(sender As Object,e As ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance Dim strFile As String = Environment.CommandLine If strFile.Length > 0 Then frmMain.FileOpen(strFile) End Sub 上面的代码的问题是,它没有获取文件路径,而是获取用于打开程序的文件(使用Open with …方法,当您右键单击文件时),它将打开程序的exe文件的位置. 当我尝试e.CommandLine时,我得到一个错误说:
解决方法
您可以处理应用程序的
StartupNextInstance event并使用e.CommandLine参数来检索所有新传递的参数的列表.
Private Sub MyApplication_StartupNextInstance(ByVal sender As Object,ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance If e.CommandLine.Count > 0 Then frmMain.FileOpen(e.CommandLine(0)) End Sub 除了Environment.GetCommandLineArgs()之外,e.CommandLine不包含应用程序的可执行路径作为第一项. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- ruby-on-rails – 获取fields_for以使用has_many
- Overview of solrconfig.xml 之 Common XML data
- ruby-on-rails – RefineryCMS Engines错误:没有
- ruby-on-rails – 如何防止Rails Console在db事务
- 中括号和大括号在正则表达式的转义,包括很多特殊
- ruby-on-rails – allowed_pa??rams – rails4和
- c – 如何使用c语言在framebuffer中绘制图形?
- ruby-on-rails – 在多个数据库中使用ActiveReco
- OEMAddressTable介绍
- c# – 在页面之间共享事件处理程序代码
热点阅读