Beispiel #1
0
        private void outputWindow_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (outputWindow.Text.Length > 0)
            {
                outputWindow.SelectionStart  = outputWindow.Text.Length;// add some logic if length is 0
                outputWindow.SelectionLength = 0;

                if (e.KeyChar == '\b')
                {
                    if (outputWindow.Text[outputWindow.Text.Length - 1] != '>')
                    {
                        outputWindow.Text = outputWindow.Text.Remove(outputWindow.Text.Length - 1);
                    }
                    e.Handled = true;
                }
                else if (e.KeyChar == '\r')
                {
                    outputWindow.ScrollToCaret();
                    int    start   = outputWindow.Text.LastIndexOf('>');
                    string command = outputWindow.Text.Substring(start + 1);
                    game.AcceptCommand(command);
                    e.Handled = true;
                }
                else
                {
                    outputWindow.ScrollToCaret();
                    outputWindow.Text += e.KeyChar;
                    e.Handled          = true;
                }
                outputWindow.SelectionStart = outputWindow.Text.Length;
                outputWindow.ScrollToCaret();
            }
        }