/*
下面的示例演示 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. Android的ExpandableListView-android学习之旅(二十八)

    ExpandableListView简介 ExpandableListView是ListView的子类,用法和ListView类似,ExpandableListView可以创建几个类别,每个类别下面又 ...

  2. 网站开发进阶(三十八)Web前端开发规范文档你需要知道的事

    Web前端开发规范文档你需要知道的事 规范目的 为提高团队协作效率, 便于后台人员添加功能及前端后期优化维护, 输出高质量的文档, 特制订此文档. 本规范文档一经确认, 前端开发人员必须按本文档规范进 ...

  3. iOS中 Swift初级入门学习(三)

    // // main.swift // LessonSwift-03 // // Copyright (c) 2015年 韩俊强. All rights reserved. // import Fou ...

  4. Demand Side Platform

    DSP特点: DSP不是从网络媒体那里包买广告位,也不是采用CPD(Cost Per Day)的方式获得广告位:而是从广告交易平台(AdExchange)来通过实时竞价的方式获得对广告进行曝光的机会, ...

  5. [TCP] 网络协议流程图

    之前在跟别人讲协议的时候总是找不到类似的图,这次再看python网络编程书籍的时候找到了一个,留存一份. 清晰的看到不同协议在不同层的传输过程!

  6. Gradle实现的两种简单的多渠道打包方法

    本来计划今天发Android的官方技术文档的翻译--<Gradle插件用户指南>的第五章的,不过由于昨天晚上没译完,还差几段落,所以只好推后了. 今天就说一下使用Gradle进行类似友盟这 ...

  7. Android Widget 开发详解(二) +支持listView滑动的widget

    转载请标明出处:http://blog.csdn.net/sk719887916/article/details/47027263 不少开发项目中都会有widget功能,别小瞧了它,他也是androi ...

  8. 基于web的jfreechart的使用

    这个模块的主要步骤就是: 前台通过struts调用后台,通过JFreeChart产生图片格式的图表,存储在某个位置,然后前台jsp再去调用图片. 来开工. JFreeChart的简介大家请百度. 首先 ...

  9. 【Qt编程】QWT在QtCreator中的安装与使用

    由于导师项目的需要,需要画图,二维+三维.三维图我用的是Qt+opengl,二维图我决定使用qwt工具库来加快我的项目进展,毕竟还有期末考试.关于Qt+opengl的使用有时间的话以后再介绍.     ...

  10. iOS监听模式系列之通知中心

    补充--通知中心 对于很多初学者往往会把iOS中的本地通知.推送通知和iOS通知中心的概念弄混.其实二者之间并没有任何关系,事实上它们都不属于一个框架,前者属于UIKit框架,后者属于Foundati ...