找了一段清屏幕的using System;
using System.Runtime.InteropServices;
using System.Text;
namespace clears
{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();
}
}
}
using System.Runtime.InteropServices;
using System.Text;
namespace clears
{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();
}
}
}
解决方案 »
- WPF tabcontrl如何动态加载页面
- winform程序设计分辩率窗体不改变
- 在VS2005里为什么我不能把控件拖到Web窗体的任意地方?
- 事件的问题
- C#大旗下的彩信开发,高手指点
- 请教:关于c#接收soap信息和发送soap消息问题
- 100高分紧急求救.net高手:C# 提取HTML源码元素坐标/属性(width,height)
- windows服务Marshal.GetActiveObject(progID)方法获取word进程
- 本地ACCESS数据上传到SQLSERVER
- 这样的列表框如何实现的?请大神源码指教...
- 请问access中的sql语言有没有关于像substring()函数功能的函数?请各位高手指教.....
- 请教 App.config 的详细使用方法
System.Console.Clear();
.NET Framework Version Information
Supported in: 2.0
再问如何将控制台内显示的内容写入一文本文件中System.Console.SetOut(new System.IO.StreamWriter("out.txt)"));
我做的是在Telnet下运行的,所以是控制台程序。
to : Macosx(AOP&.NET)
问题现在就是如何把out.txt通过程序给自动打开,而不是通过我手工的去点out.txt打开。
问题就在这里.
System.Diagnostics.Process.Start(@"c:\out.txt");
就可以了
为何在Telnet下运行就不能调用客户机上的NotePad打开呢?
怎么映射过来呢?