473,378 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 10601
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sri | last post by:
Hi, I'm having trouble specifying the classpath (to Ant) when I'm running Ant from within a servlet. Whatever directory I try to specify, Ant is trying to build the path starting at c:\ on my...
10
by: Amittai Aviram | last post by:
This XHTML 1.0 Strict page -- http://www.studiolirico.org/docs/settimana2003.html has a bilingual title in Italian and English. The principle language of the page is Italian, so the <html> tag...
11
by: Alec S. | last post by:
Hi, Is it possible to create a colored box like this? : <html> <head> <style type="text/css"> #bbb { background: #f00; position: absolute;
4
by: Bilgehan.Balban | last post by:
Hi, The following code: #include <stdio.h> // const int const_asize = 10; #define define_asize = 10; int array = {1,2,3,4,5,6,7,8,9,0};
0
by: namri | last post by:
Hi, I want to crypt a message with RSAPKCS1KeyExchangeFormatter with a RSAKey that I have. The only way that I see to do it is to get an initialize RSAPKCS1KeyExchangeFormatter with an instant...
1
by: Scott J. Peterson, MCSD, MCPSB, MCT | last post by:
I'm trying to emulate passing the 'SERVER' parameter in an NSLOOKUP using the Dns namespace, but I don't see anywhere this can be set. For example, I may do this; IPHostEntry ipEntry =...
10
by: Steve Atkins | last post by:
I have a large table (potentially tens or hundreds of millions of rows) and I need to extract some number of these rows, defined by an integer primary key. So, the obvious answer is select *...
4
by: Jason Richmeier | last post by:
I am sure this has been asked at least once before but I could not find anything when searching. If I set the value of the ExitCode property to 1066 for a windows service, the text "A service...
1
by: zufie | last post by:
Hi, I want to specifying a foreign key by altering a table. First, I create an ORDERS table without specifying a foreign key. Here is my code: CREATE TABLE ORDERS (Order_ID integer,...
2
by: Marisol2 | last post by:
I have some queries in Access 2003 db that I have setup to display as pivots. I can go into design pivot table view and click on and then click on Export to Office MicroSoft Excel. The problem is I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.