clear screen from c#

  • Thread starter Thread starter Alexander Vasilevsky
  • Start date Start date
Ah; just noticed the 2003... trickier, sorry; perhaps consider
updating? 1.x is getting harder and harder to support daily

Marc
 
Alexander said:
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
 
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

--
 
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
 
Kerem said:
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
 
Back
Top