clear screen from c#

  • Thread starter Alexander Vasilevsky
  • Start date
A

Alexander Vasilevsky

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
 
M

Marc Gravell

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

Marc
 
A

Arne Vajhøj

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
 
K

Kerem Gümrükcü

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

--
 
C

christery

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
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top