C # GUI Control Based on Input Arguments

I'm not quite sure that this is possible.

I have an outdated graphical application written in C #. Using AttachConsole (-1) (from kernel32.dll), I can add a console window if it is called from the command line. I was even able to write a module for basic use cases and make it look like a console application. I do not show the window, and if I do, it does not update and does not work properly (because I did not use Application.Run)

However, the other person on my team wants to do something similar, where the input arguments will expose a series of GUI actions (e.g. buttonExample.PerformClick (), update text fields, etc.) to simulate the user. Is it possible to do this with C # completely or will he have to use something like AutoIt?

We are using VS2008 / .NET Framework v3.5.

+4
source share
3 answers

You can add args to the string array to your static void Main() and pass them to the GUI class to do this.

  static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { ... //TODO: Stuff with your args } } 
+4
source

The answer to your question is "sorting" ... You can do something, but for the most part you will need to lay out a lot of details from your form. Here is a simple example:

 class Program { public static void Main(string[] args) { Form2 frm = new Form2(); if( args.Length >= 2 && args[0] == "something" ) { frm.txtTextArea.Text = args[1]; frm.btnOk_OnClick(frm.btnOk, EventArgs.Empty); } } } public class Form2 : Form { public TextBox txtTextArea; public Button btnOk; public void btnOk_OnClick(object sender, EventArgs e) { //... code ... } } 

I really, really, really, do not recommend doing this. You need to reorganize the implementation of the form and derive the code from the form into a business logic class.

0
source

You can use the SendInput function from user32.dll

(Of course, this should only be done if changing the GUI application is not possible).

0
source

All Articles