当前位置: 首页>>代码示例>>C#>>正文


C# Console.SetWindowSize方法代码示例

本文整理汇总了C#中System.Console.SetWindowSize方法的典型用法代码示例。如果您正苦于以下问题:C# Console.SetWindowSize方法的具体用法?C# Console.SetWindowSize怎么用?C# Console.SetWindowSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Console的用法示例。


在下文中一共展示了Console.SetWindowSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

// This example demonstrates the Console.SetWindowSize method,
//                           the Console.WindowWidth property, 
//                       and the Console.WindowHeight property.
using System;

class Sample 
{
    public static void Main() 
    {
    int origWidth, width;  
    int origHeight, height;
    string m1 = "The current window width is {0}, and the " +
                "current window height is {1}.";
    string m2 = "The new window width is {0}, and the new " +
                "window height is {1}.";
    string m4 = "  (Press any key to continue...)";
//
// Step 1: Get the current window dimensions.
//
    origWidth  = Console.WindowWidth;
    origHeight = Console.WindowHeight;
    Console.WriteLine(m1, Console.WindowWidth,
                          Console.WindowHeight);
    Console.WriteLine(m4);
    Console.ReadKey(true); 
//
// Step 2: Cut the window to 1/4 its original size.
//
    width  = origWidth/2;
    height = origHeight/2;
    Console.SetWindowSize(width, height);
    Console.WriteLine(m2, Console.WindowWidth,
                          Console.WindowHeight);
    Console.WriteLine(m4);
    Console.ReadKey(true); 
//
// Step 3: Restore the window to its original size.
//
    Console.SetWindowSize(origWidth, origHeight);
    Console.WriteLine(m1, Console.WindowWidth,
                          Console.WindowHeight);
    }
}
开发者ID:.NET开发者,项目名称:System,代码行数:43,代码来源:Console.SetWindowSize

输出:

The current window width is 85, and the current window height is 43.
  (Press any key to continue...)
The new window width is 42, and the new window height is 21.
  (Press any key to continue...)
The current window width is 85, and the current window height is 43.

示例2: Main

//引入命名空间
using System;

public class Test{
   static void Main(string[] args){


      // Change the Console appearance and redisplay.
      Console.Title = "Resized Console";
      Console.ResetColor();
      Console.Clear();
      Console.SetWindowSize(100, 50);
      Console.BufferHeight = 500;
      Console.BufferWidth = 100;
      Console.CursorLeft = 20;
      Console.CursorSize = 50;
      Console.CursorTop = 20;
      Console.CursorVisible = false;
      Console.WriteLine("Main method complete. Press Enter.");
      Console.ReadLine();

  }
}
开发者ID:C#程序员,项目名称:System,代码行数:23,代码来源:Console.SetWindowSize


注:本文中的System.Console.SetWindowSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。