📜  C#|如何更改控制台的WindowTop

📅  最后修改于: 2021-05-29 15:27:48             🧑  作者: Mango

给定普通的C#控制台,任务是更改控制台的WindowTop。

方法:可以使用C#中System包的Console类中的WindowTop属性来完成此操作。 WindowTop获取或设置控制台窗口区域相对于屏幕缓冲区的顶部位置。

程序1:获取WindowTop的价值

// C# program to illustrate the
// Console.WindowTop Property
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
  
namespace GFG {
  
class Program {
  
    static void Main(string[] args)
    {
  
        // Get the WindowTop
        Console.WriteLine("Current WindowTop: {0}",
                               Console.WindowTop);
    }
}
}

输出:

程序2:设置WindowTop的值

// C# program to illustrate the
// Console.WindowTop Property
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
  
namespace GFG {
  
class Program {
  
    static void Main(string[] args)
    {
  
        // Get the WindowWidth
        Console.WriteLine("Current WindowTop: {0}",
                               Console.WindowTop);
  
        // Set the WindowWidth
        Console.BufferHeight = 100;
        Console.WindowTop = 10;
  
        // Get the WindowWidth
        Console.Write("Current WindowTop: {0}",
                            Console.WindowTop);
    }
}
}

输出:

注意:在两个图像中,请参见“窗口”右侧的“垂直滚动条”。