469,133 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

Specifying command-line arguments w/WinForms mangles Form

Hi,

I have seen a million examples of using command-line parameters in the
following manner:

[STAThread]
static void Main(string[] args)
{
Application.Run(new frmMain(args));
}
public frmMain(string[] args):this()
{

if (args.Length>0)
{
if (args[0].ToUpper().Equals("PUT"))
m_AutomatedFTPMethod = FTPMethods.UploadingFile ;
else if (args[0].ToUpper().Equals("GET"))
m_AutomatedFTPMethod = FTPMethods.DownloadingFile ;
}
}

This actually works fine, but at some point, my form is wiped clean of all
controls and I am left with simply a blank form (plus any code I have
written). Is this structure only meant for Console applications? I've
also looked into the Environment.GetCommandLineArgs method, but I'm afraid
that may return different results based on the OS.

Any ideas?

Thanks,

David

Nov 16 '05 #1
3 10443
I expect this is because you have overridden the default constructor,
therefore the constructor for the parent.form class is not being called.
I could be wrong of course. Do you have a simple full app that you can share
that shows your problem.
Maybe with just a single button on it or something.

Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
C# Ebook at http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html
VB Ebook at http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html

"David Adams" <me*****@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have seen a million examples of using command-line parameters in the
following manner:

[STAThread]
static void Main(string[] args)
{
Application.Run(new frmMain(args));
}
public frmMain(string[] args):this()
{

if (args.Length>0)
{
if (args[0].ToUpper().Equals("PUT"))
m_AutomatedFTPMethod = FTPMethods.UploadingFile ;
else if (args[0].ToUpper().Equals("GET"))
m_AutomatedFTPMethod = FTPMethods.DownloadingFile ;
}
}

This actually works fine, but at some point, my form is wiped clean of all
controls and I am left with simply a blank form (plus any code I have
written). Is this structure only meant for Console applications? I've
also looked into the Environment.GetCommandLineArgs method, but I'm afraid
that may return different results based on the OS.

Any ideas?

Thanks,

David

Nov 16 '05 #2
You could test this by not using the constructor and using something like a
public static in frmMain.

public class FormMain
{
public static string[] Args = null;
public frmMain() {...}

static void Main(string[] args)
{
FormMain.Args = args;
Application.Run(new frmMain());
}

private void SomeMethod()
{
string[] args = FormMain.Args;
if ....
}
}

--
William Stacey, MVP

"David Adams" <me*****@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have seen a million examples of using command-line parameters in the
following manner:

[STAThread]
static void Main(string[] args)
{
Application.Run(new frmMain(args));
}
public frmMain(string[] args):this()
{

if (args.Length>0)
{
if (args[0].ToUpper().Equals("PUT"))
m_AutomatedFTPMethod = FTPMethods.UploadingFile ;
else if (args[0].ToUpper().Equals("GET"))
m_AutomatedFTPMethod = FTPMethods.DownloadingFile ;
}
}

This actually works fine, but at some point, my form is wiped clean of all
controls and I am left with simply a blank form (plus any code I have
written). Is this structure only meant for Console applications? I've
also looked into the Environment.GetCommandLineArgs method, but I'm afraid
that may return different results based on the OS.

Any ideas?

Thanks,

David


Nov 16 '05 #3
Thank you both for your suggestions. William, your code snippet worked
perfectly and didn't "hose" my form! Thanks.

David
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Amittai Aviram | last post: by
4 posts views Thread by Bilgehan.Balban | last post: by
1 post views Thread by Scott J. Peterson, MCSD, MCPSB, MCT | last post: by
10 posts views Thread by Steve Atkins | last post: by
4 posts views Thread by Jason Richmeier | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.