C#控制台如何清屏呀?谢了先
大家帮帮忙哈,不知道的也帮忙顶一下哈,谢谢哈
大家帮帮忙哈,不知道的也帮忙顶一下哈,谢谢哈
解决方案 »
- 设置 FormBorderStyle.None 时,子窗体首次加载不能最大化。要第二次才可以
- C# 怎么启动ie
- sql中有没自动根据内容变长的数据类型
- 简单的 Web应用程序设计
- 有没有判断一个值是否为数值型的函数
- 求助为什么经过图片没有任何反应啊
- 类的动态实例化问题!高手请进。
- SOCKET网络编程时异步数据响应
- C#中能否实现象PB的datawindow一样的强大功能呢?比如分组,增加计算列等等??
- TextBox的显示格式,比如我想在BOX中加入一个“¥”符号,想让用户输入的所有数字都自动跟随到“¥”后面
- 如何修改c#应用程序发出的soap request包
- c#向access数据库写入的问题 急!!!!!
没看懂,windows下还要清屏吗?还是你在用控制台程序
System.Console.Clear()
.net framework 2.0
谢谢大家 ding
namespace clears
{
using System;
using System.Runtime.InteropServices;
using System.Text;
class StdHandleEnum
{
public const int STD_INPUT_HANDLE = -10;
public const int STD_OUTPUT_HANDLE = -11;
public const int STD_ERROR_HANDLE = -12;
}; // This sructure contains a screen coordinate.
class cls
{
internal struct COORD
{
public short X;
public short Y;
} // This stucture contains information about the
// console screen buffer.
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD Size;
public COORD p1;
public short a1;
public short w1;
public short w2;
public short w3;
public short w4;
public COORD m1;
} // We need these four functions from KERNEL32.DLL.
// The GetStdHandle() function returns a handle to any
// standard input or output.
[DllImport("kernel32.dll")]
public static extern int GetStdHandle(int nStdHandle); // The GetConsoleScreenBufferInfo() returns information
// about the console screen buffer so we know how much to
// clear.
[DllImport("kernel32.dll")]
public static extern bool GetConsoleScreenBufferInfo(int hConsoleOutput, out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo); // The SetConsoleCursorPosition() places the cursor on
// the console screen.
[DllImport("kernel32.dll")]
public static extern bool SetConsoleCursorPosition(int hConsoleOutput, COORD dwCursorPosition); // The FillConsoleOutputCharacter() allows us to place
// any character on the console screen. Using a space
// clears the display area.
[DllImport("kernel32.dll",SetLastError=true,CharSet=CharSet.Auto)]
public static extern bool FillConsoleOutputCharacter(int hConsoleOutput, short cCharacter, int nLength, COORD WriteCoord, out int lpNumberOfCharsWritten); [STAThread]
static void Main(string[] args)
{
// Needed ask Windows about the console screen
// buffer settings.
CONSOLE_SCREEN_BUFFER_INFO CSBI;
// Handle to the output device.
int hOut;
// Number of characters written to the screen.
int CharOut;
// Home cursor position.
COORD Home; // Write some data to the screen.
Console.Write("Clear the Screnn!" +
"\r\nPress any key...");
Console.ReadLine(); // Clear the screen.
// Begin by getting a handle to the console screen.
hOut = GetStdHandle(StdHandleEnum.STD_OUTPUT_HANDLE); // Get the required console screen buffer information.
GetConsoleScreenBufferInfo(hOut, out CSBI ); // Set the home position for the cursor.
Home.X = 0;
Home.Y = 0; // Fill the console with spaces.
FillConsoleOutputCharacter(hOut,
(short) ' ',
CSBI.Size.X * CSBI.Size.Y,
Home,
out CharOut); // Place the cursor in the upper left corner.
SetConsoleCursorPosition(hOut, Home); // Show the screen is clear.
Console.ReadLine();
}
}
}