Q:

Let user start typing when winform pops up without them having to click on the textbox

I am working on a barcode reader project in Visual Studio using C#. I have created a WinForm Application and have added a RichTextBox to it. I want the user to be able to start scanning when they open the program without having to click on the textbox. 
Thanks in advance!

A:

(I'm assuming you have an application with a multitude of stuff in it. However there is one field that needs to be filled in with a scanned barcode.)
I faced a simular issue a while ago. I needed to capture a barcode in WPF. Setting the focus property in load seemed a good idea but because there were a multitude of other controls on the page that the user could click etc. focus jumped from one control to the other, making the barcode go in the wrong fields or vanish in a grid that has focus for example.
We were not able to use any other way of reading the barcode from the scanner because it was used for other applications too. It had to be configured as input.
We came up with a solution of capturing the keypresses instead. 
By using the keydown events we could track the scanner input and stated that if more than 5 keys came in within a limited time + with our prefix and suffix it had to be a barcode.
EDIT: here is a simplified version of the class.
public delegate void BarcodeRead(string barcode);

public class ManualReader
{
    private string barcode = "no barcode detected";
    private string possible = "";
    private DateTime timestarted = DateTime.MinValue;
    private Timer InputTimeout;
    public BarcodeRead OnBarcodeRead;

    public void OnKeyDown(object sender, KeyEventArgs.KeyEventArgs e)
    {

        //create timer if it does not exist
        if (InputTimeout == null)
        {
            InputTimeout = new Timer(100);
            InputTimeout.Enabled = true;
            InputTimeout.Elapsed += new ElapsedEventHandler(OnTimedEvent);
        }
        //reset timer
        InputTimeout.Stop();
        InputTimeout.Start();

        //possible barcode
        possible += CharToKey.GetCharFromKey(e);
        if (timestarted == DateTime.MinValue)
        {
            timestarted = DateTime.Now;
        }
    }

    //Timer elapses
    private void OnTimedEvent(object sender, ElapsedEventArgs e)
    {
        //Is it a barcode?
        if ((timestarted.AddMilliseconds(600) > DateTime.Now) && (possible.Length > 5)
                && (timestarted != DateTime.MinValue) && possible.Contains("\r"))
        {
            barcode = possible;
            barcode = barcode.Remove(0, 1);
            barcode = barcode.Replace("\r", "");
            //launch delegate
            if (OnBarcodeRead != null)
            {
                OnBarcodeRead.Invoke(barcode);                    
            }
        }

        //delete timers
        timestarted = DateTime.MinValue;
        InputTimeout.Dispose();
        InputTimeout = null;
        possible = null;
    }

  }
}

I'm aware that for really short timeouts datetime functions aren't precise but still this little 'hack' worked perfectly for our application.

