TreeNode.BackColor Property
Gets or sets the background color of the tree node.
[Visual Basic] Public Property BackColor As Color [C#] public Color BackColor {get; set;} [C++] public: __property Color get_BackColor(); public: __property void set_BackColor(Color); [JScript] public function get BackColor() : Color; public function set BackColor(Color);
Property Value
The background Color of the tree node.
Remarks
If the BackColor property is set to a null reference (Nothing in Visual Basic), the Color used is the BackColor property value of the TreeView control that the tree node is assigned to.
Example
[Visual Basic, C#, C++] The following 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 assumes you have a TreeView control on a Form with a collection of TreeNode objects.
[Visual Basic] Public Sub HighlightCheckedNodes() Dim countIndex As Integer = 0 Dim selectedNode As String = "Selected customer nodes are : " Dim myNode As TreeNode For Each myNode In myTreeView.Nodes(0).Nodes ' Check whether the tree node is checked. If myNode.Checked Then ' Set the node's backColor. myNode.BackColor = Color.Yellow selectedNode += myNode.Text + " " countIndex += 1 Else myNode.BackColor = Color.White End If Next myNode If countIndex > 0 Then MessageBox.Show(selectedNode) Else MessageBox.Show("No nodes are selected") End If End Sub [C#] public void HighlightCheckedNodes() { int countIndex = 0; string selectedNode = "Selected customer nodes are : "; foreach (TreeNode myNode in myTreeView.Nodes[0].Nodes) { // Check whether the tree node is checked. if(myNode.Checked) { // Set the node's backColor. myNode.BackColor = Color.Yellow; selectedNode += myNode.Text+" "; countIndex++; } else myNode.BackColor = Color.White; } if(countIndex > 0) MessageBox.Show(selectedNode); else MessageBox.Show("No nodes are selected"); } [C++] public: void HighlightCheckedNodes() { int countIndex = 0; String* selectedNode = S"Selected customer nodes are : "; IEnumerator* myEnum = myTreeView->Nodes->Item[0]->Nodes->GetEnumerator(); while (myEnum->MoveNext()) { TreeNode* myNode = __try_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, S" "); countIndex++; } else myNode->BackColor = Color::White; } if (countIndex > 0) MessageBox::Show(selectedNode); else MessageBox::Show(S"No nodes are selected"); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
TreeNode Class | TreeNode Members | System.Windows.Forms Namespace | ForeColor