/*
下面的示例演示 WindowLeft、WindowTop、WindowWidth、WindowHeight、BufferWidth、BufferHeight 和 CursorVisible 属性以及

SetWindowPosition、SetBufferSize 和 ReadKey 方法。该示例在屏幕缓冲区中根据屏幕缓冲区的宽度绘制一个网格模式。然后,该示例在

按下向上键、向下键、向左键或向右键这四个控制台键时相应移动控制台窗口。网格模式有助于查看控制台窗口相对于屏幕缓冲区的移动。
*/

// This example demonstrates the Console.WindowLeft and
// Console.WindowTop properties.
using System;
using System.Text;
using System.IO;
//
class Sample
{
public static int saveBufferWidth;
public static int saveBufferHeight;
public static int saveWindowHeight;
public static int saveWindowWidth;
public static bool saveCursorVisible;
//
public static void Main()
{
string m1 = "1) Press the cursor keys to move the console window.\n" +
"2) Press any key to begin. When you're finished...\n" +
"3) Press the Escape key to quit.";
string g1 = "+----";
string g2 = "| ";
string grid1;
string grid2;
StringBuilder sbG1 = new StringBuilder();
StringBuilder sbG2 = new StringBuilder();
ConsoleKeyInfo cki;
int y;
//
try
{
saveBufferWidth = Console.BufferWidth;
saveBufferHeight = Console.BufferHeight;
saveWindowHeight = Console.WindowHeight;
saveWindowWidth = Console.WindowWidth;
saveCursorVisible = Console.CursorVisible;
//
Console.Clear();
Console.WriteLine(m1);
Console.ReadKey(true);

// Set the smallest possible window size before setting the buffer size.
Console.SetWindowSize(1, 1);
Console.SetBufferSize(80, 80);
Console.SetWindowSize(40, 20);

// Create grid lines to fit the buffer. (The buffer width is 80, but
// this same technique could be used with an arbitrary buffer width.)
for (y = 0; y < Console.BufferWidth/g1.Length; y++)
{
sbG1.Append(g1);
sbG2.Append(g2);
}
sbG1.Append(g1, 0, Console.BufferWidth%g1.Length);
sbG2.Append(g2, 0, Console.BufferWidth%g2.Length);
grid1 = sbG1.ToString();
grid2 = sbG2.ToString();

Console.CursorVisible = false;
Console.Clear();
for (y = 0; y < Console.BufferHeight-1; y++)
{
if (y%3 == 0)
Console.Write(grid1);
else
Console.Write(grid2);
}

Console.SetWindowPosition(0, 0);
do
{
cki = Console.ReadKey(true);
switch (cki.Key)
{
case ConsoleKey.LeftArrow:
if (Console.WindowLeft > 0)
Console.SetWindowPosition(
Console.WindowLeft-1, Console.WindowTop);
break;
case ConsoleKey.UpArrow:
if (Console.WindowTop > 0)
Console.SetWindowPosition(
Console.WindowLeft, Console.WindowTop-1);
break;
case ConsoleKey.RightArrow:
if (Console.WindowLeft < (Console.BufferWidth-Console.WindowWidth))
Console.SetWindowPosition(
Console.WindowLeft+1, Console.WindowTop);
break;
case ConsoleKey.DownArrow:
if (Console.WindowTop < (Console.BufferHeight-Console.WindowHeight))
Console.SetWindowPosition(
Console.WindowLeft, Console.WindowTop+1);
break;
}
}
while (cki.Key != ConsoleKey.Escape); // end do-while
} // end try
catch (IOException e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.Clear();
Console.SetWindowSize(1, 1);
Console.SetBufferSize(saveBufferWidth, saveBufferHeight);
Console.SetWindowSize(saveWindowWidth, saveWindowHeight);
Console.CursorVisible = saveCursorVisible;
}
} // end Main
} // end Sample
/*
This example produces results similar to the following:

1) Press the cursor keys to move the console window.
2) Press any key to begin. When you're finished...
3) Press the Escape key to quit.

...

+----+----+----+-
| | | |
| | | |
+----+----+----+-
| | | |
| | | |
+----+----+----+-

*/

J#
// This example demonstrates the Console.WindowLeft and
// Console.WindowTop properties.
import System.*;
import System.Text.*;
import System.IO.*;
//
class Sample
{
public static int saveBufferWidth;
public static int saveBufferHeight;
public static int saveWindowHeight;
public static int saveWindowWidth;
public static boolean saveCursorVisible;
//
public static void main(String[] args)
{
String m1 = "1) Press the cursor keys to move the console window.\n"
+ "2) Press any key to begin. When you're finished...\n"
+ "3) Press the Escape key to quit.";
String g1 = "+----";
String g2 = "| ";
String grid1;
String grid2;
StringBuilder sbG1 = new StringBuilder();
StringBuilder sbG2 = new StringBuilder();
ConsoleKeyInfo cki;
int y;
//
try {
saveBufferWidth = Console.get_BufferWidth();
saveBufferHeight = Console.get_BufferHeight();
saveWindowHeight = Console.get_WindowHeight();
saveWindowWidth = Console.get_WindowWidth();
saveCursorVisible = Console.get_CursorVisible();
//
Console.Clear();
Console.WriteLine(m1);
Console.ReadKey(true);

// Set the smallest possible window size before setting the buffer
// size.
Console.SetWindowSize(1, 1);
Console.SetBufferSize(80, 80);
Console.SetWindowSize(40, 20);

// Create grid lines to fit the buffer. (The buffer width is 80, but
// this same technique could be used with an arbitrary buffer width.)
for (y = 0; y < Console.get_BufferWidth() / g1.get_Length(); y++) {
sbG1.Append(g1);
sbG2.Append(g2);
}

sbG1.Append(g1, 0, Console.get_BufferWidth() % g1.get_Length());
sbG2.Append(g2, 0, Console.get_BufferWidth() % g2.get_Length());
grid1 = sbG1.ToString();
grid2 = sbG2.ToString();

Console.set_CursorVisible(false);
Console.Clear();
for (y = 0; y < Console.get_BufferHeight() - 1; y++) {
if (y % 3 == 0) {
Console.Write(grid1);
}
else {
Console.Write(grid2);
}
}
Console.SetWindowPosition(0, 0);
do {
cki = Console.ReadKey(true);
switch (cki.get_Key()) {
case ConsoleKey.LeftArrow :
if (Console.get_WindowLeft() > 0) {
Console.SetWindowPosition(Console.get_WindowLeft()-1,
Console.get_WindowTop());
}
break;
case ConsoleKey.UpArrow :
if (Console.get_WindowTop() > 0) {
Console.SetWindowPosition(Console.get_WindowLeft(),
Console.get_WindowTop() - 1);
}
break;
case ConsoleKey.RightArrow :
if (Console.get_WindowLeft() < Console.get_BufferWidth()
- Console.get_WindowWidth()) {
Console.SetWindowPosition(Console.get_WindowLeft()+1,
Console.get_WindowTop());
}
break;
case ConsoleKey.DownArrow :
if (Console.get_WindowTop() < Console.get_BufferHeight()
- Console.get_WindowHeight()) {
Console.SetWindowPosition(Console.get_WindowLeft(),
Console.get_WindowTop() + 1);
}
break;
}
} while (!(cki.get_Key().Equals(ConsoleKey.Escape))); // end do-while
} // end try
catch (IOException e) {
Console.WriteLine(e.get_Message());
}
finally {
Console.Clear();
Console.SetWindowSize(1, 1);
Console.SetBufferSize(saveBufferWidth, saveBufferHeight);
Console.SetWindowSize(saveWindowWidth, saveWindowHeight);
Console.set_CursorVisible(saveCursorVisible);
}
} //end main
} //end Sample
/*
This example produces results similar to the following:

1) Press the cursor keys to move the console window.
2) Press any key to begin. When you're finished...
3) Press the Escape key to quit.

...

+----+----+----+-
| | | |
| | | |
+----+----+----+-
| | | |
| | | |
+----+----+----+-

*/

经典Console案例的更多相关文章

  1. 使用MapReduce实现一些经典的案例

    在工作中,很多时候都是用hive或pig来自动化执行mr统计,但是我们不能忘记原始的mr.本文记录了一些通过mr来完成的经典的案例,有倒排索引.数据去重等,需要掌握. 一.使用mapreduce实现倒 ...

  2. PE经典DIY案例1:全解开方案让量产PE也能

    更新说明:因未来的uefi似乎并不能识别并引导ud区,但能识别和引导量产和u+B+隐藏或高端隐藏区,故解决量产PE对u+B+隐藏区的支持,并增加对UEFI启动支持,已经成为PE制作的最主流技术. PE ...

  3. 18个awk的经典实战案例

    介绍 这些案例是我收集起来的,大多都是我自己遇到过的,有些比较经典,有些比较具有代表性. 这些awk案例我也录了相关视频的讲解awk 18个经典实战案例精讲,欢迎大家去瞅瞅. 插入几个新字段 在&qu ...

  4. Spring框架-经典的案例和demo,一些可以直接用于生产,使用atomikos来处理多数据源的一致性事务等

    Spring Examples Demo website:http://www.ityouknow.com/ 对Spring框架的学习,包括一些经典的案例和demo,一些可以直接用于生产. sprin ...

  5. 快要C语言考试了,大学生们收好这些经典程序案例,包你考试过关!

    距离考试越来越近 编程大佬早已饥渴难耐 电脑小白还在瑟瑟发抖 但是不要怕! 来看看这些经典程序案例 包你考试过关! [程序1] 有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多 ...

  6. JAVA并发,经典死锁案例-哲学家就餐

    转自:http://blog.csdn.net/tayanxunhua/article/details/38691005 死锁经典案例:哲学家就餐. 这个案例会导致死锁. 通过修改<Java编程 ...

  7. MySQL数据库“十宗罪”【十大经典错误案例】

    原文作者:张甦 来源:http://blog.51cto.com/sumongodb 今天就给大家列举 MySQL 数据库中,最经典的十大错误案例,并附有处理问题的解决思路和方法,希望能给刚入行,或数 ...

  8. CISCO ASA 5505 经典配置案例

    nterface Vlan2 nameif outside  ----------------------------------------对端口命名外端口  security-level 0 -- ...

  9. C语言经典88案例,我文科妹妹说她都学会了!

    案例ex01: 将字符串转换为一个整数 1 题目 函数:fun() 功能:将字符串转换为一个整数 描述: [不能使用C语言提供的字符串函数] 输入:字符串"-1234" 输出:整型 ...

随机推荐

  1. 一个简单程序快速入门JDBC

    首先创建jdbc的库,再在这个库里面创建一张users表. drop database if exists jdbc; create database if not exists jdbc; use ...

  2. Windows Server2008R2、2012R2重置系统开机登陆密码

    平时用的虚拟机太多导致经常会忘记密码,这里分享两个链接,分别对应的是08R2和12R2重置密码的方法. 08R2:http://ucweb.blog.51cto.com/4042188/962284 ...

  3. MySql下视图的创建

     (1).第一类:create view v as select * from table; (2).第二类:create view v as select id,name,age from ta ...

  4. 《java入门第一季》之Socket编程通信和TCP协议通信图解

    Socket编程通信图解原理: TCP协议通信图解

  5. BIP Requests Are Failing With Error "OPP Error Oracle.apps.xdo.XDOException: Error Creating Lock Fil

    In this Document   Symptoms   Cause   Solution   References Applies to: BI Publisher (formerly XML P ...

  6. Linux的资源管理器

    说是资源管理器,其实就是使用命令来对Linux运行系统的参数的查看.下面就一起看一看怎么像在windows下查看资源管理器吧. 1.查看进程(额,自然是电脑上正在运行的进程咯) ps aux 其中a ...

  7. sublime test2 快捷键

    快捷键比较全的:http://blog.useasp.net/archive/2013/06/14/sublime-text-2-all-default-Shortcuts-table-on-wind ...

  8. 【shell脚本练习】批量添加用户和设置密码

    题目 添加9个用户,user101-user109:密码同用户名: 思路 for循环来添加就好了,用户名和密码都可以拼字符串来完成 user10+数字 要判断是否能添加成功,注意非交互模式下修改用户密 ...

  9. android官方技术文档翻译——Case 标签中的常量字段

    本文译自androd官方技术文档<Non-constant Fields in Case Labels>,原文地址:http://tools.android.com/tips/non-co ...

  10. 7、Libgdx网络操作

    (官网:www.libgdx.cn) Libgdx包含了一些跨平台的网络操作类,这些类在Gdx.net中. 特性 跨平台HTTP请求 多平台TCP C/S Socket支持(可配置) TCP C/S优 ...