c#的控制台程序如何能使其 1打开就全屏,2改变其中的颜色,很急~
请高手帮帮我
请高手帮帮我
解决方案 »
- 密码键盘开发包
- listview中Items的forcolor或者backcolor更改闪烁的问题?
- DataGridView.Columns.Clear() 会释放 DataGridViewColumn对象所占用的空间吗?
- c# 支持多种字体的文本控件
- 将C#界面签入Delphi5程序中的消息问题
- 求助数据库插入记录的时候如何能返回自动编号字段?
- windows2003升级sp1以后,TreeView不能显示菜单了
- 请问这是啥原因?
- .NET部署问题,有没有人遇到过定义了Uninstall方法却没有执行的情况
- Visual Studio中,怎麼自動添加namespace的引用。
- 请问C#控制台程序中如何实现清屏?
- 请问一下数组中的Rank属性具体怎么应用
using System;
using System.Runtime.InteropServices; // for DllImport attribute
namespace color_console
{
class Class1
{
static void Main(string[] args)
{
Class1 c =new Class1();
c.change();
} [DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetConsoleTextAttribute(
IntPtr hConsoleOutput,
CharacterAttributes wAttributes);
/* declaring the setconsoletextattribute function*/ [DllImport("kernel32.dll")]
public static extern IntPtr GetStdHandle(int nStdHandle);
/*declaring the getstdhandle funtion to get thehandle
that would be used in setConsoletextattribute function */ void change()
{
IntPtr hOut; /* declaring variable to get handle*/
hOut= GetStdHandle(-11);/* -11 is sent for output device*/ /*Displaying text in different colors and background colors*/ SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_BLUE );
Console.WriteLine(" Subhan ALLAH "); SetConsoleTextAttribute(hOut, CharacterAttributes.BACKGROUND_RED);
Console.WriteLine(" Alkhamdolillah ");
SetConsoleTextAttribute(hOut, CharacterAttributes.BACKGROUND_GREEN );
Console.WriteLine(" Allah O Akbar ");
SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_RED );
Console.WriteLine(" Pakistan ");
Console.ReadLine();
}
/* This enumeration lists all of the character attributes.
You can combine attributes to achieve specific effects.*/
public enum CharacterAttributes
{
FOREGROUND_BLUE = 0x0001,
FOREGROUND_GREEN = 0x0002,
FOREGROUND_RED = 0x0004,
FOREGROUND_INTENSITY = 0x0008,
BACKGROUND_BLUE = 0x0010,
BACKGROUND_GREEN = 0x0020,
BACKGROUND_RED = 0x0040,
BACKGROUND_INTENSITY = 0x0080,
COMMON_LVB_LEADING_BYTE = 0x0100,
COMMON_LVB_TRAILING_BYTE = 0x0200,
COMMON_LVB_GRID_HORIZONTAL = 0x0400,
COMMON_LVB_GRID_LVERTICAL = 0x0800,
COMMON_LVB_GRID_RVERTICAL = 0x1000,
COMMON_LVB_REVERSE_VIDEO = 0x4000,
COMMON_LVB_UNDERSCORE = 0x8000
}
}
}
**********************************
*本人主要使用VB+MS SQL,C#略知一二
*
*如有相关问题需要帮助
*
*可发短消息告知链接
*
*助人为快乐之本!
**********************************
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized; Rectangle rect = Screen.PrimaryScreen.Bounds;
this.Size = rect.Size;
this.Location = rect.Location;
this.TopMost = true; //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}