How to set ForeColor for a TreeNode?

牧云@^-^@ 提交于 2019-12-11 06:47:16

问题


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;

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?


回答1:


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

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"


来源:https://stackoverflow.com/questions/46975130/how-to-set-forecolor-for-a-treenode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!