[英]Powershell Winform RichTextBox Colors?
我一直在尋找解決這個問題的方法。 (嘗試將其解碼幾乎沒有成功: http : //poshcode.org/4123 http://poshcode.org/4123 http://msdn.microsoft.com/zh-cn/library/dd30h2yb(v=vs.110 ).aspx )
這似乎應該很簡單,但我仍在努力弄清楚。 似乎唯一的方法是使用selectionstart,selectionlength,selectioncolor,然后在打印時取消選擇。 我猜想我可能必須在算法上找出僅選擇所需的Richtextbox位置的方法。 我想在嘗試之前先問一下。
問題:
您如何選擇從另一行開始選擇?
有沒有一種方法可以只為我想要的選擇着色,而無需在Richtextbox中手動選擇位置?**?
是否有一般更好的方法來完成此操作?
另外,有人知道Powershell專用的Winforms有什么好的資源或參考嗎?
請幫忙。 謝謝。
這是我正在嘗試做的事情:
function UserInformation {
$userdata = Get-ADUser $34 -properties *
## IF LOCKED OUT, MAKE RED ##
if ($userdata.lockedout -eq $false) {
$outputBox.SelectionStart = #????
$outputBox.SelectionLength = #????
$outputBox.SelectionColor = [Drawing.Color]::Green
elseif ($userdata.lockedout -eq $true) {
$outputBox.SelectionStart = #????
$outputBox.SelectionLength = #????
$outputBox.SelectionColor = [Drawing.Color]::Red
}
## GUI ##
$outputBox = New-Object System.Windows.Forms.RichTextBox #creating the text box
$outputBox.Location = New-Object System.Drawing.Size(5,40)
$outputBox.Size = New-Object System.Drawing.Size(565,200)
$outputBox.MultiLine = $True
$outputBox.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor
[System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left
$outputBox.ScrollBars = "Vertical"
$Form.Controls.Add($outputBox)
您的帖子將近一年了,您可能已經找到了解決方案,但是我很幸運,通過使用ForeColor屬性使用RichTextBox表單。
https://msdn.microsoft.com/zh-CN/library/system.windows.forms.richtextbox_properties(v=vs.110).aspx
這是我在PowerShell中的代碼:
$outputBox = New-Object System.Windows.Forms.RichTextBox
$outputBox.Location = New-Object System.Drawing.Size(8,175)
$outputBox.Size = New-Object System.Drawing.Size(870,428)
$outputBox.Font = New-Object System.Drawing.Font("Lucida Console",16)
$outputBox.ForeColor = [Drawing.Color]::Green
$outputBox.MultiLine = $True
$outputBox.ReadOnly = $True
然后根據需要排成一行(在此示例中更改為Green)
$outputBox.Font = New-Object System.Drawing.Font("Trebuchet MS",14)
$outputBox.ForeColor = [Drawing.Color]::Green
$outputBox.text="Please standby as we connect to Office 365. Updating commands ..."
要使此工作正常進行,您需要在每個新添加的行之前添加一個選擇。 新行必須通過以下方式添加:
AppendText()
另外,您必須在末尾設置換行符,用`n換行。
$outputBox.SelectionColor = [Drawing.Color]::Green
$outputBox.AppendText("text here...`n")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.