Vb.net 传递参数时不要打开窗体
我有一个典型的表单,有列表框、文本框、按钮等等。此表单实质上加载配置文件(.cfg)并填充对象。然后,用户可以根据对象中的内容(来自文件)来“生成”报告 但是-我希望用户能够使用命令行参数加载.cfg文件并生成报告。这里需要注意的是,仍然在屏幕上加载对象会更容易(这样我就不必创建更多代码来生成报告) 为此,到目前为止,我创建了以下代码:Vb.net 传递参数时不要打开窗体,vb.net,winforms,Vb.net,Winforms,我有一个典型的表单,有列表框、文本框、按钮等等。此表单实质上加载配置文件(.cfg)并填充对象。然后,用户可以根据对象中的内容(来自文件)来“生成”报告 但是-我希望用户能够使用命令行参数加载.cfg文件并生成报告。这里需要注意的是,仍然在屏幕上加载对象会更容易(这样我就不必创建更多代码来生成报告) 为此,到目前为止,我创建了以下代码: Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load If my
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
If my.Application.CommandLineArgs.count > 0 then
me.Hide()
with my.Application
'Load the specific file
LoadCfgFile(.CommandLineArgs(0))
'GenerateReport
GenerateCSVReport()
'Exit Application
application.Exit()
end with
End If
End Sub
问题是,在生成报告时,表单确实会在一瞬间显示,我更希望它在使用参数运行时永远不会显示自己。执行此操作的正确位置是在应用程序的
启动
事件处理程序中,而不是在启动表单中
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
' The following events are available for MyApplication:
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
If e.CommandLine.Count > 0 Then
'Do whatever here.
'...
'Exit without creating the startup form.
e.Cancel = True
End If
End Sub
End Class
End Namespace
您可以从项目属性的应用程序页面访问该代码文件。然后将该代码移动到表单的构造函数或Sub-Main(您可能更喜欢后者)。将对象加载到屏幕部分会更容易。不清楚。您不使用数据生成报表吗?为什么要使用控件的属性?这些属性用于显示数据,而不是作为源。