Загрузка...

[C#] Block Console Input

Тема в разделе C# создана пользователем r3xq1 13 фев 2019. 171 просмотр

  1. r3xq1
    r3xq1 Автор темы 13 фев 2019 https://t.me/DarkSoft_Extra 119 27 июл 2018
    Написал простой класс локер который не даёт писать в консоль как буквы так и цифры и.т.д

    CSHARP
     using System;

    public class Locker
    {
    public static string ConsoleInput(bool status = true)
    {
    while (true)
    {
    ConsoleKeyInfo a = Console.ReadKey(status);
    string str = string.Empty;
    if (int.TryParse(a.KeyChar.ToString(), out int i) != char.IsDigit(a.KeyChar))
    {
    Console.Write(a.KeyChar);
    str += a.KeyChar;
    }
    if (a.Key == ConsoleKey.Backspace)
    {
    int currentCursorPos = Console.CursorLeft;
    Console.SetCursorPosition(currentCursorPos, Console.CursorTop);
    if (str.Length > 0)
    {
    str = str.Substring(0, str.Length - 1);
    }
    Console.SetCursorPosition(currentCursorPos + str.Length, Console.CursorTop);
    }
    }
    }
    }
    Вызов ConsoleInput в любом месте.
     
Загрузка...
Top