2011-09-29 169 views
1

這工作:控制PowerShell控制檯窗口位置

(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 

但是,這並不工作,我不知道如何使它發揮作用:

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

我得到的錯誤是奇怪。它抱怨「緩衝」當我試圖設置外窗的位置:

Exception setting "WindowPosition": "Cannot use the 
specified Window X (column) position because it extends 
past the width of the screen buffer. Specify another X 
position, starting with 0 as the left most column of 
the buffer. 

回答

4

的錯誤不是真的很奇怪,因爲WindowPosition Gets and sets the position, in characters, of the view window relative to the screen buffer.

它不會設置窗口的位置,而是把它粗暴地說,在窗口視圖中看到的緩衝區中的位置。所以在你的情況下,你會得到錯誤,因爲它在緩衝區之外。

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

不幸的是,設置窗口的位置並不簡單。這裏是它的一個管理單元雖然 - http://wasp.codeplex.com/(使用Set-WindowPosition

+0

是的,它的確在做這件事。好的,那很奇怪......誰需要那個? – djangofan