| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1876 人关注过本帖
标题:[求助]
只看楼主 加入收藏
znn2788
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-1-29
收藏
 问题点数:0 回复次数:14 
[求助]
    请帮帮忙,c#里 清屏 和 退出 是怎么写的。我意思是在COS界面下的。谢谢各位了。
搜索更多相关主题的帖子: COS 界面 
2005-01-29 19:06
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
system("cls");
exit(0);

C++的。C#好象没对DOS的函数
2005-01-29 19:36
znn2788
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-1-29
收藏
得分:0 
    谢谢你,不过不是。我查了msdn也查不到,但是,我想c++有,c#也应该有的。
2005-01-30 09:08
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
我知道不是,我也查不到。C#好象没
2005-01-30 09:44
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
[转帖]清屏1

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(); } } } fupip(小贝)大大的帖子 http://search.csdn.net/Expert/topic/1418/1418868.xml?temp=.9960443 -_____________-b

2005-01-30 10:23
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
[转帖]清屏2
Win32Native.COORD coord1;
      coord1 = new Win32Native.COORD();
      IntPtr ptr1 = Console.ConsoleOutputHandle;
      if (ptr1 == Win32Native.INVALID_HANDLE_VALUE)
      {
            throw new IOException(Environment.GetResourceString("));
      }
      Win32Native.CONSOLE_SCREEN_BUFFER_INFO console_screen_buffer_info1 = Console.GetBufferInfo();
      int num1 = console_screen_buffer_info1.dwSize.X * console_screen_buffer_info1.dwSize.Y;
      int num2 = 0;
      bool flag1 = Win32Native.FillConsoleOutputCharacter(ptr1, ' ', num1, coord1, out num2);
      if (!flag1)
      {
            __Error.WinIOError();
      }
      num2 = 0;
      flag1 = Win32Native.FillConsoleOutputAttribute(ptr1, console_screen_buffer_info1.wAttributes, num1, coord1, out num2);
      if (!flag1)
      {
            __Error.WinIOError();
      }
      flag1 = Win32Native.SetConsoleCursorPosition(ptr1, coord1);
      if (!flag1)
      {
            __Error.WinIOError();
      }
2005-01-30 10:23
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
很确定地证实,在C#中并没有直接的对DOS清屏的方法,都是一些调用kernel32.dll(Windows系统核心)的方法,是很麻烦,没办法,将就一下吧!
2005-01-30 10:25
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
另外,试试这样,呵呵:

Console.Write("cls/n");
2005-01-30 10:25
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
这个也是一种方法,不过有缺陷:

System.Diagnostics.Process.Start(cmd.exe cls);
2005-01-30 10:28
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
这是面向Windows下的图形编程的清屏:

Graphics canvas = this.CreateGraphics();
try
{
canvas.Clear(this.BackColor);
}
finally
{
//The Graphics reference must be disposed once we are finished
//with it
canvas.Dispose();
}
2005-01-30 10:29
快速回复:[求助]
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015939 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved