Running a windows form project from commandline

R

RSH

Hi,

I have a silly question...

I have a Windows Form project (VB.Net) that was created in Visual Studio
2003. The project runs great.

Now I have to add the ability to run the same application from a
commandline. The obvious issue is going to be with all of the form specific
settings...luckily I wrote the app using classes to seperate the form
specific logic from the business logic.

The issue i have however, is that if I change the Startup object in the
project properties from "Form1" to "SubMain" and then check for commandline
arguments if none exist then I'm instantiating the Form object as follows:

Public Class Form1

Inherits System.Windows.Forms.Form

Public Shared Sub main(ByVal CmdArgs() As String)

if CmdArgs.length > 0 then

Dim frm As New Form1

frm.ShowDialog()

else

RunCmdApp()

end if

End Sub

end class

This all seems to work fine from the Commandline, BUT now when there are no
commandline arguments a simple blank form shows (not my form which has all
sorts of controls and such). The class name is Form1 but the filename is
frmMain.vb but that doesnt seem to have anything to do with it.

What am I missing? I want my form back.

Thanks,
Ron
 
C

Chris Dunaway

The issue i have however, is that if I change the Startup object in the
project properties from "Form1" to "SubMain" and then check for commandline
arguments if none exist then I'm instantiating the Form object as follows:

You code seems to instantiate the form if there *is* command line
arguments
Public Class Form1

Inherits System.Windows.Forms.Form

Public Shared Sub main(ByVal CmdArgs() As String)

if CmdArgs.length > 0 then

Dim frm As New Form1

frm.ShowDialog()

else

RunCmdApp()

end if

End Sub

end class

This all seems to work fine from the Commandline, BUT now when there are no
commandline arguments a simple blank form shows (not my form which has all

Again, your code only instantiates the form if CmdArgs.Length > 0

It should show the form you designed. Could you copy the exact code
that you use? Or provide a short but complete example that
demonstrates the problem? You might also try this instead:

If CmdArgs.Length > 0 Then
RunCmdApp()
Else
Application.Run(New Form1)
End If

Is the code you provided all there is to the Form1 class?

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top