TreeNode::BackColor Property
.NET Framework (current version)
Gets or sets the background color of the tree node.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Property Value
Type: System.Drawing::ColorThe background Color of the tree node. The default is Color::Empty.
If the BackColor property is set to Color::Empty, the Color used is the BackColor property value of the TreeView control that the tree node is assigned to.
The following code example highlights any TreeNode objects a TreeView control that has its Checked property set to true by setting its BackColor property to Yellow. This code requires that you have a TreeView control on a Form with a collection of TreeNode objects.
public: void HighlightCheckedNodes() { int countIndex = 0; String^ selectedNode = "Selected customer nodes are : "; IEnumerator^ myEnum = myTreeView->Nodes[ 0 ]->Nodes->GetEnumerator(); while ( myEnum->MoveNext() ) { TreeNode^ myNode = safe_cast<TreeNode^>(myEnum->Current); // Check whether the tree node is checked. if ( myNode->Checked ) { // Set the node's backColor. myNode->BackColor = Color::Yellow; selectedNode = String::Concat( selectedNode, myNode->Text, " " ); countIndex++; } else myNode->BackColor = Color::White; } if ( countIndex > 0 ) MessageBox::Show( selectedNode ); else MessageBox::Show( "No nodes are selected" ); }
.NET Framework
Available since 1.1
Available since 1.1
Show: