So I tried to code an userinput with ConsoleKeyInfo. Its works. Than I tried to implement an cancellation when Esc is pressed. It works aswell but it cuts off some of my Writeline. When I try the same code with checking for example M it works just fine!
Is someone able to help?
My Code:
class Program
{
static void Main()
{
while (true)
{
string eingabeArtikelnummer, eingabePlatzalter;
Console.Clear();
Console.Write("Ein neuer Artikel wird angelegt:\n\nGeben Sie die Artikelnummer an: ");
eingabePlatzalter = SteuerungUndEingabe();
if (eingabePlatzalter == ConsoleKey.Escape.ToString()) { break; }
else { eingabeArtikelnummer = eingabePlatzalter; }
}
WartenAufUser();
}
static string SteuerungUndEingabe()
{
ConsoleKey input;
string userEingabe = null;
do
{
input = Console.ReadKey().Key;
if (input == ConsoleKey.Escape)
{
userEingabe = input.ToString();
break;
}
userEingabe += input.ToString();
} while (input != ConsoleKey.Enter);
return (userEingabe);
}
static void WartenAufUser()
{
Console.WriteLine("----------------------------------------------------------------------------------------\n\nBeliebige Taste druecken um ins Menue zu gelangen!");
while (Console.ReadKey() == null) { };
}
}
}
This is the output in the Console:
This is how it should be:
Edit:
So I asked my Teacher how to fix this Problem. He had no idea why it occurs but he recommanded me to go around the Problem and change my Writeline to
Console.WriteLine("x\n----------------------------------------------------------------------------------------\n\nBeliebige Taste druecken um ins Menue zu gelangen!");
The "x\n" miraculously avoids the problem :D

