473,509 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arguments to windows app

Jay
I have a windows app that looks like a dialog box.
It displaya a message, with Yes/No buttons.
And the Message can be different each time the windows app is started.
Can I pass in the message as an argument into the windows app, so that I can
display that?
Oct 26 '06 #1
2 4977
On Thu, 26 Oct 2006 15:32:02 -0500, Jay wrote:
I have a windows app that looks like a dialog box.
It displaya a message, with Yes/No buttons.
And the Message can be different each time the windows app is started.
Can I pass in the message as an argument into the windows app, so that I can
display that?
Change your Main method to the following:

static void Main(string[] args)

You can then read the args passed in and send them on to your form through
a property or method to be displayed. Ex:

string message = string.Empty;

if (args.Length 0)
message = args[0];
Form1 frm = new Form1();
frm.CommandMessage = message;
Application.Run(frm);

This assumes you've added the string property CommandMessage to your Form1
class.
--
Tom Porterfield
Oct 26 '06 #2
Sure. Let's assume your form is Form1 and the label you want to change based
on arguments is label1.

First you need to modify the static main method that studio geneted -
(in 2.0 this is in program.cs file, in 1.1 it's in the form1 itself).

Change:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
To:
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1(args));
}

With that done overload the contructor of Form1:

public Form1(string[] args)
{
// Do Necessary Validations and Check before this line.
InitializeComponent();
label1.Text = args[0];
}
In other words - we take the arguments from Main - pass it to the forms
contructor and do whatever we want to do with the arguments in the forms
constructor.

I gave a quick test of this apporach on 2.0 - let me know if you're using
1.1 and have any problems.

Cheers,
rajiv.

"Jay" wrote:
I have a windows app that looks like a dialog box.
It displaya a message, with Yes/No buttons.
And the Message can be different each time the windows app is started.
Can I pass in the message as an argument into the windows app, so that I can
display that?
Oct 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7139
by: Eric Chong | last post by:
I created a Windows Service in C# that requires to get passed command arguments like a Console App. I noticed that there is an option "Start parameters" text box in the property of a Windows...
10
3259
by: Agent Mulder | last post by:
Hi group, Almost 3 weeks ago I posted a short question here and in comp.std.c++ and I got exactly 1 respons, from Kevin Goodsell. He said he didn't want it. I post it here again, this time in a...
2
3418
by: SC | last post by:
I'm trying to hide command line arguments passed to a C++/Qt application compiled for Windows. Under Linux, I replaced argc in the main with empty spaces and it works, a 'ps -ef' does not show...
12
2784
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of...
7
4715
by: Steve M | last post by:
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the...
2
2035
by: melanieab | last post by:
Hi, I kind of got thrown into C# without any real programming experience, so I know this is probably an easy question, but it's driving me crazy. In my Tabs class, as I'm leaving a tabpage, I'm...
41
2498
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum +=...
9
16796
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
4
4146
by: Milan | last post by:
How do you pass in arguments from the command line to a .Net windows app. Senario: vb.net application should be able to execute from command prompt by passing login and password and should be...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.