共用方式為


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

範例

下列程式碼範例會藉由將其 CheckedBackColor 屬性設定 trueYellow ,反白顯示控制項設定為 的任何 TreeNode 物件 TreeView 。 此程式碼需要您在 上 Form 具有 TreeView 物件集合的 TreeNode 控制項。

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 則所使用的 是 BackColor 樹狀節點指派給控制項的 TreeView 屬性值。 Color.Empty

適用於

另請參閱