Delete Lines

Posts 12 of 2 · Page 1 of 1
Delete Lines
With this you can delete x Lines from your C# consoleapplication.
Its very help and useful, so you mustn't redraw anything.

Code:
 public static void ClearLastConsoleLines(int count)
        {
            int cursorTop = Console.CursorTop;
            if ((count == cursorTop) || (count == 0))
            {
                Console.Clear();
            }
            else if ((count < cursorTop) && (count > 0))
            {
                string str = new string(' ', Console.WindowWidth * count);
                Console.SetCursorPosition(0, cursorTop - count);
                Console.Write(str);
                Console.SetCursorPosition(0, cursorTop - count);
            }
        }
Quote Originally Posted by 0x01337 View Post
With this you can delete x Lines from your C# consoleapplication.
Its very help and useful, so you mustn't redraw anything.

Code:
 public static void ClearLastConsoleLines(int count)
        {
            int cursorTop = Console.CursorTop;
            if ((count == cursorTop) || (count == 0))
            {
                Console.Clear();
            }
            else if ((count < cursorTop) && (count > 0))
            {
                string str = new string(' ', Console.WindowWidth * count);
                Console.SetCursorPosition(0, cursorTop - count);
                Console.Write(str);
                Console.SetCursorPosition(0, cursorTop - count);
            }
        }
Nice one

Here is one for a RichTextBox Control: (Sorry any mistakes)
Code:
public void LineEdit(int Line, string NewValue, bool Clear = false)
        {
            int LinesLengh = richTextBox1.Lines.Length;
            if (Line >= LinesLengh)
                MessageBox.Show("Error - Line don't Exsist!");
            else
            {
                string[] TempData = richTextBox1.Lines;
                TempData[Line] = NewValue;
                richTextBox1.Lines = TempData;
            }
            if (Clear)
                richTextBox1.Clear();
        }
Example usage:
Code:
LineEdit(1, "Wonder");

For console usage, I think you could just replace the: richTextBox1.Lines with Console.Lines
Posts 12 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?