CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

C#控制台如何清屏呀?谢了先

楼主justioo(周银辉)2005-05-28 11:03:14 在 .NET技术 / C# 提问

C#控制台如何清屏呀?谢了先  
  大家帮帮忙哈,不知道的也帮忙顶一下哈,谢谢哈 问题点数:20、回复次数:9Top

1 楼webfactory(jack)回复于 2005-05-28 11:56:20 得分 2

清屏???!!!  
  没看懂,windows下还要清屏吗?还是你在用控制台程序Top

2 楼wmt85(深山老翁)回复于 2005-05-28 12:03:41 得分 3

自己参考一下,http://www.c-sharpcorner.com/Code/2002/May/ExtendSysConsole.aspTop

3 楼syeerzy(快乐永远*先天下之乐而乐*后天下之忧而忧*)回复于 2005-05-28 12:19:37 得分 0

cls?Top

4 楼fabian(蓝色布谷鸟)回复于 2005-05-28 12:41:36 得分 2

我也不太明白,不过帮你顶一下吧。Top

5 楼Macosx(结贴)回复于 2005-05-28 13:12:47 得分 2

搜一下   以前问过好多次了  
  System.Console.Clear()  
  .net   framework   2.0Top

6 楼justioo(周银辉)回复于 2005-05-28 18:24:10 得分 0

控制台程序的清屏哈,  
  谢谢大家   dingTop

7 楼JunlanGuo(SillyGirl)回复于 2005-06-08 10:19:35 得分 1

没找到System.Console.Clear()Top

8 楼deyunanhai(bocelli)回复于 2005-06-08 10:47:45 得分 0

调用cmd,然后使用cls就可以了Top

9 楼JunlanGuo(SillyGirl)回复于 2005-06-08 13:05:07 得分 10

找到了一个清屏的例子  
  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();  
  }  
  }  
  }  
  Top

相关问题

  • 关于C#控制台清屏的问题
  • 非常简单的C#问题 怎么在控制台(黑屏)下生成.dll
  • C#的控制台程序用 什么对屏幕输入、输出?
  • c#控制台程序一问
  • C#控制台自动关闭问题
  • c#调用控制台程序
  • VC控制台程序的清屏函数是? C语言里面的函数clrscr()好像没有?
  • 控制台分屏幕输出问题
  • 关于控制台清屏的问题
  • 如何在VC控制台下运行C程序

关键词

  • c#
  • 控制台
  • 清屏
  • coord
  • short
  • clears
  • screen
  • console
  • handle
  • constint std

得分解答快速导航

  • 帖主:justioo
  • webfactory
  • wmt85
  • fabian
  • Macosx
  • JunlanGuo
  • JunlanGuo

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo