TreeNode.BackColor Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the background color of the tree node.
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
The background Color of the tree node. The default is Empty.
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" );
}
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
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.
Продукт | Версії |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Відгук про .NET
.NET – це проект із відкритим кодом. Виберіть посилання, щоб надати відгук: