BASIC's CLS equivalent in C#

This is a discussion on BASIC's CLS equivalent in C# within the C# Programming forums, part of the General Programming Boards category; Is there a method in C# that will clear the screen and place the cursor at 1,1 in a CLI? ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    BASIC's CLS equivalent in C#

    Is there a method in C# that will clear the screen and place the cursor at 1,1 in a CLI? I would've thought it would be in System.Console, but I couldn't find anything event remotely like it.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    When I read your post I immediatly thought there must be a System.Console.ClearScreen...

    But as it seems, there is no such function. Have a look here for Microsofts suggestion. I hoped they were just kidding, but apparantly they are not
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    interesting how every programmer at some point in time needs to clear the console somehow and yet they just keep making it harder and harder to do
    My Website

    "Circular logic is good because it is."

  4. #4
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    The easiest way is to output blank lines. I believe the number is 25. I might be a little off since I haven't worked with C# in a while (lost the CD I put the SDK on).

    Code:
    for (int index = 0; index < 24; index++) {
        System.Console.WriteLine("");
      }
    The console in .NET is extremely weak. If you want more advanced abilities you'd be better off writing a component that mimics the command prompt. Or just painting a form black and drawing text to it using the Lucida Console font.

    Edit: Stupid code tags don't function in quick post. :P
    Last edited by Frobozz; 07-24-2004 at 09:30 PM.

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    In most cases that would work. The problem is that first of all, the cursor is now at the bottom, and I don't think there's an easy way to position the cursor (like BASIC's Location). Also, you can change the number of lines in the console window when you're the user.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  2. Pointer equivalent to array notation
    By bekkilyn in forum C Programming
    Replies: 4
    Last Post: 12-06-2006, 07:22 PM
  3. Replies: 10
    Last Post: 08-17-2005, 11:17 PM
  4. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 10:31 PM
  5. Equivalent of BASIC's run?
    By sean in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-02-2002, 12:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21