TreeNode.BackColor 属性

定义

获取或设置树节点的背景色。

public:
 property System::Drawing::Color BackColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public System.Drawing.Color BackColor { get; set; }
member this.BackColor : System.Drawing.Color with get, set
Public Property BackColor As Color

属性值

树节点的背景 Color。 默认值为 Empty

示例

下面的代码示例通过将 控件Checked的 属性设置为 来突出显示其BackColor属性Yellow设置为 true 的任何TreeNode对象TreeView。 此代码要求在 上具有 TreeView 对象集合的 TreeNode 控件Form

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

注解

如果 属性 BackColor 设置为 Color.EmptyColor 则使用的 是 BackColor 树节点分配到的 TreeView 控件的属性值。

适用于

另请参阅