开发者

Controlling window position of a Powershell console

开发者 https://www.devze.com 2023-04-09 04:53 出处:网络
This works: (Get-Host).UI.RawUI $a = (Get-Host).UI.RawUI $a.BackgroundColor = \"white\" $a.ForegroundColor = \"black\"

This works:

(Get-Host).UI.RawUI
$a = (Get-Host).UI.RawUI
$a.BackgroundColor = "white"
$a.ForegroundColor = "black"

$size = (Get-Host).UI.RawUI.WindowSize
$size.Width = 80
$size.Height = 30
(Get-Host).UI.RawUI.WindowSize = $size

But this doesn't work, and I am not sure how to make it work:

$position = (Get-Host).UI.RawUI.Windowposition
$position.X = 0
$position.Y = 30
(Get-Host).UI.RawUI.Windowposition = $position

The error I get is strange. It complains about "buffer" when I am trying to set external window position:

Exception setting "WindowPosition": "Cannot use the 
specified Window X (column) position becau开发者_开发技巧se it extends 
past the width of the screen buffer. Specify another X 
position, starting with 0 as the left most column of 
the buffer.


The error is not really strange, because WindowPosition Gets and sets the position, in characters, of the view window relative to the screen buffer.

It does not set the position of the Window, but to put it crudely, the position in the buffer that you see through the view of the window. So in your case, you are getting the error because it is outside the buffer.

http://msdn.microsoft.com/en-us/library/system.management.automation.host.pshostrawuserinterface.windowposition%28v=vs.85%29.aspx

Unfortunately, setting the position of the window is not simple. There is a snapin for it though - http://wasp.codeplex.com/ ( use Set-WindowPosition)


Take a look at this script: Resize-Console.ps1 – Resize console window/buffer using arrow keys.

It is hopefully useful itself and partially should answer the question (the size part).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号