clear screen from c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Vasilevsky

    #1

    clear screen from c#

    How to clear the screen in the console application in Microsoft Visual C #.
    NET 2003.

    http://www.alvas.net - Audio tools for C# and VB.Net developers + Christmas
    discount


  • Marc Gravell

    #2
    Re: clear screen from c#

    Console.Clear()

    http://msdn2.microsoft.com/en-us/lib...ole.clear.aspx

    Marc

    Comment

    • Marc Gravell

      #3
      Re: clear screen from c#

      Ah; just noticed the 2003... trickier, sorry; perhaps consider
      updating? 1.x is getting harder and harder to support daily

      Marc

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: clear screen from c#

        Alexander Vasilevsky wrote:
        How to clear the screen in the console application in Microsoft Visual C #.
        NET 2003.
        Write 25 empty lines.

        Or use a hack like:

        using System;
        using System.Runtime. InteropServices ;

        class MainClass
        {
        [DllImport("msvc rt.dll")]
        public static extern int system(string cmd);
        public static void Main(string[] args)
        {
        Console.WriteLi ne("Hello world");
        system("CLS");
        Console.WriteLi ne("Hello world");
        }
        }

        Arne

        Comment

        • Kerem Gümrükcü

          #5
          Re: clear screen from c#

          Hi Arne,

          >Write 25 empty lines.
          Useless if your consoles height is wider
          than 25 Lines. So this is no usefull aproach!
          And it allocates additional memory you dont
          have to do,...you want to free something
          and not to allocate more,...

          >Or use a hack like:
          >using System;
          >using System.Runtime. InteropServices ;
          >class MainClass
          >{
          [DllImport("msvc rt.dll")]
          public static extern int system(string cmd);
          public static void Main(string[] args)
          {
          Console.WriteLi ne("Hello world");
          system("CLS");
          Console.WriteLi ne("Hello world");
          }
          >}
          Its ok, but not needed here. Do not call any
          c-runtime functions until there is really a need for
          it. Here you can use Marc's suggestion "Console.Cl ear"
          which is just fine.Or use "FillConsoleOut putCharacter" or
          "FillConsoleOut putAttribute" with pre-calls
          to "GetConsoleScre enBufferInfo" to get the
          needed information,... but here you will allocate
          extra space for the cleaning memory, so you
          dont have to do this,...

          CLS is ok, but much better is Console.Clear, since
          it is runtime handled!

          Regards

          Kerem

          --
          -----------------------
          Beste Grüsse / Best regards / Votre bien devoue
          Kerem Gümrükcü
          Microsoft Live Space: http://kerem-g.spaces.live.com/
          Latest Open-Source Projects: http://entwicklung.junetz.de
          -----------------------
          "This reply is provided as is, without warranty express or implied."


          Comment

          • christery@gmail.com

            #6
            Re: clear screen from c#

            CLS is ok, but much better is Console.Clear, since
            it is runtime handled!
            >
            Regards
            >
            Kerem
            Think someone ment that Clear only handeld in

            ..NET Framework 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0

            Went down that way myself... (still missing chr$(12))

            //CY

            Comment

            • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

              #7
              Re: clear screen from c#

              Kerem Gümrükcü wrote:
              >Write 25 empty lines.
              >
              Useless if your consoles height is wider
              than 25 Lines.
              Then write some more lines.
              Here you can use Marc's suggestion "Console.Cl ear"
              which is just fine.
              CLS is ok, but much better is Console.Clear, since
              it is runtime handled!
              The original poster wrote:

              #in Microsoft Visual C # .NET 2003

              Marc wrote:

              #Console.Clear( )

              # perhaps consider
              #updating? 1.x is getting harder and harder to support daily

              Console.Clear is new in 2.0 (2005).
              Or use "FillConsoleOut putCharacter" or
              "FillConsoleOut putAttribute" with pre-calls
              to "GetConsoleScre enBufferInfo" to get the
              needed information,
              That is a possibility too.

              Arne

              Comment

              Working...