How do i use C# app to reflect data on other app textbox.

  • Thread starter Thread starter mcl chan
  • Start date Start date
M

mcl chan

Hello all,

I'm using below code for c# app to call another app

{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc Enable.RaisingEvents=false;
proc StartInfo.Filename="anotherapp.exe" ;
proc StartInfor.Arguments="1234";
proc Start();
}
I'm able to call up anotheapp.exe within c# app successfully but the
data (1234) that i wanted in anotherapp.exe 's inputbox is blank.

Is there any way round to achieve this condition ?

Thanks for your help .

mcl
 
I'm not exactly sure about what you want to achieve. You are mentioning an
"inputbox". What do you mean? Do you mean a TextBox control, an instance of
TextBox class? If yes, then your other app has a GUI.

In your sample code you put the string "1234" into proc.StartInfo.Arguments.
This way you specify the command line arguments for the other app. Is the
other app a console application (without GUI)?

When you assign the value "1234" to proc.StartInfo.Arguments you specify the
command line arguments. Now when you look at the entry point of the other
app it will typically look something like this for a console application:

[STAThread]
static void Main(string[] args) {
// ... your code goes here
}

If you want to access any command line arguments, then just examine the args
string array, e.g. args[0]. You might want to check, whether any arguments
have passed at all, e.g by using args.Length:

[STAThread]
static void Main(string[] args) {
if( args.Length > 0 ) {
// access arguments with subscript, e.g. args[0].
// Sample:
string firstArgument = args[0];
}
}

For a Windows application, it typically looks like this:

[STAThread]
static void Main() {
Application.Run(new MainForm());
}

In order to receive command line parameters, modify the latter to:

[STAThread]
static void Main(string[] args) {
Application.Run(new MainForm());
}

Furthermore, if the textbox is a control on MainForm, you can write:

[STAThread]
static void Main(string[] args) {
Application.Run(new MainForm(args));
}

Accordingly you would have to change the constructor for the class MainForm
so that it takes a parameter, and in the constructor you can assign your
textbox the value:

public class MainForm : System.Windows.Forms.Form {
public MainForm(string[] args) {
_theTextBox.Text = args[0];
}
//... other code ...
private System.Windows.Forms.TextBox _theTextBox;
}

I hope this sheds some light onto your question.

Best regards,
Manfred.
 
to get Arguments in anotheapp.exe use below

string[] Arguments = Environment.GetCommandLineArgs();

To call anotheapp.exe on button1 click u need below code
private void button1_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc Enable.RaisingEvents=false;
proc.StartInfo.FileName="anotheapp.exe" ;
proc.StartInfo.Arguments="1234";
proc.Start();
}

HTH

sswalia
MCSD, OCA, MCAD
 
Back
Top