clear screen from c# - CSharp

This is a discussion on clear screen from c# - CSharp ; 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...

+ Reply to Thread
Results 1 to 7 of 7

clear screen from c#

  1. Default 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



  2. Default Re: clear screen from c#


  3. Default 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

  4. Default 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("msvcrt.dll")]
    public static extern int system(string cmd);
    public static void Main(string[] args)
    {
    Console.WriteLine("Hello world");
    system("CLS");
    Console.WriteLine("Hello world");
    }
    }

    Arne

  5. Default 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("msvcrt.dll")]
    > public static extern int system(string cmd);
    > public static void Main(string[] args)
    > {
    > Console.WriteLine("Hello world");
    > system("CLS");
    > Console.WriteLine("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.Clear"
    which is just fine.Or use "FillConsoleOutputCharacter" or
    "FillConsoleOutputAttribute" with pre-calls
    to "GetConsoleScreenBufferInfo" 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."



  6. Default 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

  7. Default 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.Clear"
    > 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 "FillConsoleOutputCharacter" or
    > "FillConsoleOutputAttribute" with pre-calls
    > to "GetConsoleScreenBufferInfo" to get the
    > needed information,


    That is a possibility too.

    Arne

+ Reply to Thread