如何为 TreeNode 设置前景色? [英] How to set ForeColor for a TreeNode?
问题描述
我使用 powershell 代码创建了一个树视图,但现在我想在创建过程中更改节点的颜色,具体取决于节点的类型.我试过这个 =>
I created a treeview using powershell code but now i want to change the color of the node during the creation depends of the type of the node. I tried this =>
$newNode = new-object System.Windows.Forms.TreeNode
$newNode.ForeColor = Color.Blue;
但它不起作用,我收到了类似术语‘Color.Blue’未被识别为 cmdlet 的名称"的错误消息.有人成功了吗?
But it's not working, i got an error like "The term 'Color.Blue' is not recognized as the name of a cmdlet". Anyone succeed to do it?
推荐答案
如果你打算在编写代码时使用类型化颜色并且也有智能感知,你可以使用:
If you are going to use a typed color and also have intellisense when writing code, you can use:
$newNode.ForeColor = [System.Drawing.Color]::Blue
此外,由于颜色转换器可以将颜色名称和 R、G、B 值转换为颜色,您还可以使用以下选项:
Also, since the color converter can convert color name and R,G,B value to color, you also can use following options:
$newNode.ForeColor = "Blue"
$newNode.ForeColor = "0,0,255"
这篇关于如何为 TreeNode 设置前景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!