TreeNode::BackColor Property

 

Gets or sets the background color of the tree node.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
property Color BackColor {
	Color get();
	void set(Color value);
}

Property Value

Type: System.Drawing::Color

The 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
Return to top
Show: