Export (0) Print
Expand All

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 Color BackColor { get; set; }
/** @property */
public Color get_BackColor ()

/** @property */
public void set_BackColor (Color value)

public function get BackColor () : Color

public function set BackColor (value : Color)

Not applicable.

Property Value

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 : ";
   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");
}

public void HighlightCheckedNodes()
{
    int countIndex = 0;
    String selectedNode = "Selected customer nodes are : ";
    for (int iCtr = 0; iCtr < myTreeView.get_Nodes().get_Item(0).
        get_Nodes().get_Count(); iCtr++) {
        TreeNode myNode = myTreeView.get_Nodes().get_Item(0).
            get_Nodes().get_Item(iCtr);
        // Check whether the tree node is checked.
        if (myNode.get_Checked()) {
            // Set the node's backColor.
            myNode.set_BackColor(Color.get_Yellow());
            selectedNode += myNode.get_Text() + " ";
            countIndex++;
        }
        else {
            myNode.set_BackColor(Color.get_White());
        }
    }
    if (countIndex > 0) {
        MessageBox.Show(selectedNode); 
    }
    else {
        MessageBox.Show("No nodes are selected");
    }
} //HighlightCheckedNodes

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft