0

Forgive me, I'm a newbie and I'm completing a task for an interview where I'm encouraged to ask for help online (hence why the request is weird).

I have a form that is saved externally that looks like this: https://i.stack.imgur.com/gCnTY.jpg

The task is calling for a console application to input numbers into the form and then copy the label value (see the #2 by the equals button) and save it to memory for output in the console.

Here is the code that I have now - I'm completely unaware of how to even reference the label and was looking for ideas!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;




namespace ConsoleApplication19
{
    class Program
   {
    static void Main(string[] args)
    {
        System.Diagnostics.Process.Start(@"C:\Users\Jenna\Documents\Visual     Studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\bin\Release\WindowsFormsApplication4.exe");

        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("6");
            Thread.Sleep(500);
            System.Windows.Forms.SendKeys.SendWait("{TAB}");
            Thread.Sleep(500);
            System.Windows.Forms.SendKeys.SendWait("0");
            Thread.Sleep(500);
            System.Windows.Forms.SendKeys.SendWait("{TAB}"); 
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{DOWN}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{DOWN}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{DOWN}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{DOWN}");
        Thread.Sleep(500); 
        System.Windows.Forms.SendKeys.SendWait("{TAB}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{ENTER}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{TAB}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{ENTER}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{TAB}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{TAB}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{BACKSPACE}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("3");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{TAB}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{TAB}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{ENTER}");
        Thread.Sleep(500);
        System.Windows.Forms.SendKeys.SendWait("{TAB}");
        Thread.Sleep(500);


    }
}

}

Icemanind
  • 47,519
  • 50
  • 171
  • 296
  • Are you allowed to modify the WinForms application? Or only the console application? – Icemanind Jun 15 '15 at 17:53
  • 1
    Just an opinion, but you should probably find a way to do this without all the Thread.Sleep() calls. To clarify, your program needs to start an external Windows program and then enter data into it, then read data back that is displayed by the application on screen? – Brendan Hannemann Jun 15 '15 at 17:55
  • Yes, I just wanted it to go slow to show that all of the necessary requested steps were being followed. Is there a better way to do that? – jennaisavol Jun 15 '15 at 17:56
  • @jennaisavol - Are you allowed to reference the WinForms application inside the Console Application? – Icemanind Jun 15 '15 at 17:57
  • Unless the requirements specify that you need to go slow, it adds unnecessary noise to the code. – Brendan Hannemann Jun 15 '15 at 17:57
  • @Icemanind (Sorry if this sounds super undeducated - I honestly don't know what I'm doing) I have had it both ways - when I had the winform inside the program.cs file I couldn't get the sendkeys function to work. Now I have the form in a seperate windows forms application that I've built out. I can go into that file and edit as necessary and rebuild the exe. – jennaisavol Jun 15 '15 at 17:58
  • You may be able to just redirect standard I/O to fill out the form. Take a look at this: https://stackoverflow.com/questions/415620/redirect-console-output-to-textbox-in-separate-program?rq=1 – Brendan Hannemann Jun 15 '15 at 17:59
  • @jennaisavol - If you're allowed to include a reference to the WInForms application from the console application, then you got it easy! All you have to do is instantiate the form from your console application, then create some properties to access the textboxes and the label. – Icemanind Jun 15 '15 at 18:01

0 Answers0