TreeViewDrawMode 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义表示 TreeView 的绘制方法的常数。
public enum class TreeViewDrawMode
public enum TreeViewDrawMode
type TreeViewDrawMode =
Public Enum TreeViewDrawMode
- 继承
字段
Normal | 0 | TreeView 由操作系统绘制。 |
OwnerDrawAll | 2 | TreeView 节点的所有元素均为手动绘制,包括图标、复选框、加号和减号以及连接节点的线。 |
OwnerDrawText | 1 | TreeView 节点的标签部分均为手动绘制。 其他节点元素由操作系统绘制,包括图标、复选框、加号和减号以及连接节点的线。 |
示例
下面的代码示例演示如何使用控件的所有者绘制功能自定义 TreeView 控件。 TreeView示例中的 控件在标准节点标签旁边显示可选节点标记。 使用 TreeNode.Tag 属性指定节点标记。 控件 TreeView 还使用自定义颜色,包括自定义突出显示颜色。
可以通过设置颜色属性来自定义大多数 TreeView 颜色,但选择突出显示颜色不能作为属性使用。 此外,默认选择突出显示矩形仅围绕节点标签扩展。 必须使用所有者绘图来绘制节点标记,并绘制足够大以包含节点标记的自定义突出显示矩形。
有关完整示例,请参阅 TreeView.DrawNode 参考主题。
TreeViewOwnerDraw()
{
tagFont = gcnew System::Drawing::Font( "Helvetica",8,FontStyle::Bold );
// Create and initialize the TreeView control.
myTreeView = gcnew TreeView;
myTreeView->Dock = DockStyle::Fill;
myTreeView->BackColor = Color::Tan;
myTreeView->CheckBoxes = true;
// Add nodes to the TreeView control.
TreeNode^ node;
for ( int x = 1; x < 4; ++x )
{
// Add a root node to the TreeView control.
node = myTreeView->Nodes->Add( String::Format( "Task {0}", x ) );
for ( int y = 1; y < 4; ++y )
{
// Add a child node to the root node.
node->Nodes->Add( String::Format( "Subtask {0}", y ) );
}
}
myTreeView->ExpandAll();
// Add tags containing alert messages to a few nodes
// and set the node background color to highlight them.
myTreeView->Nodes[ 1 ]->Nodes[ 0 ]->Tag = "urgent!";
myTreeView->Nodes[ 1 ]->Nodes[ 0 ]->BackColor = Color::Yellow;
myTreeView->SelectedNode = myTreeView->Nodes[ 1 ]->Nodes[ 0 ];
myTreeView->Nodes[ 2 ]->Nodes[ 1 ]->Tag = "urgent!";
myTreeView->Nodes[ 2 ]->Nodes[ 1 ]->BackColor = Color::Yellow;
// Configure the TreeView control for owner-draw and add
// a handler for the DrawNode event.
myTreeView->DrawMode = TreeViewDrawMode::OwnerDrawText;
myTreeView->DrawNode += gcnew DrawTreeNodeEventHandler( this, &TreeViewOwnerDraw::myTreeView_DrawNode );
// Add a handler for the MouseDown event so that a node can be
// selected by clicking the tag text as well as the node text.
myTreeView->MouseDown += gcnew MouseEventHandler( this, &TreeViewOwnerDraw::myTreeView_MouseDown );
// Initialize the form and add the TreeView control to it.
this->ClientSize = System::Drawing::Size( 292, 273 );
this->Controls->Add( myTreeView );
}
public TreeViewOwnerDraw()
{
// Create and initialize the TreeView control.
myTreeView = new TreeView();
myTreeView.Dock = DockStyle.Fill;
myTreeView.BackColor = Color.Tan;
myTreeView.CheckBoxes = true;
// Add nodes to the TreeView control.
TreeNode node;
for (int x = 1; x < 4; ++x)
{
// Add a root node to the TreeView control.
node = myTreeView.Nodes.Add(String.Format("Task {0}", x));
for (int y = 1; y < 4; ++y)
{
// Add a child node to the root node.
node.Nodes.Add(String.Format("Subtask {0}", y));
}
}
myTreeView.ExpandAll();
// Add tags containing alert messages to a few nodes
// and set the node background color to highlight them.
myTreeView.Nodes[1].Nodes[0].Tag = "urgent!";
myTreeView.Nodes[1].Nodes[0].BackColor = Color.Yellow;
myTreeView.SelectedNode = myTreeView.Nodes[1].Nodes[0];
myTreeView.Nodes[2].Nodes[1].Tag = "urgent!";
myTreeView.Nodes[2].Nodes[1].BackColor = Color.Yellow;
// Configure the TreeView control for owner-draw and add
// a handler for the DrawNode event.
myTreeView.DrawMode = TreeViewDrawMode.OwnerDrawText;
myTreeView.DrawNode +=
new DrawTreeNodeEventHandler(myTreeView_DrawNode);
// Add a handler for the MouseDown event so that a node can be
// selected by clicking the tag text as well as the node text.
myTreeView.MouseDown += new MouseEventHandler(myTreeView_MouseDown);
// Initialize the form and add the TreeView control to it.
this.ClientSize = new Size(292, 273);
this.Controls.Add(myTreeView);
}
Public Sub New()
' Create and initialize the TreeView control.
myTreeView = New TreeView()
myTreeView.Dock = DockStyle.Fill
myTreeView.BackColor = Color.Tan
myTreeView.CheckBoxes = True
' Add nodes to the TreeView control.
Dim node As TreeNode
Dim x As Integer
For x = 1 To 3
' Add a root node to the TreeView control.
node = myTreeView.Nodes.Add(String.Format("Task {0}", x))
Dim y As Integer
For y = 1 To 3
' Add a child node to the root node.
node.Nodes.Add(String.Format("Subtask {0}", y))
Next y
Next x
myTreeView.ExpandAll()
' Add tags containing alert messages to a few nodes
' and set the node background color to highlight them.
myTreeView.Nodes(1).Nodes(0).Tag = "urgent!"
myTreeView.Nodes(1).Nodes(0).BackColor = Color.Yellow
myTreeView.SelectedNode = myTreeView.Nodes(1).Nodes(0)
myTreeView.Nodes(2).Nodes(1).Tag = "urgent!"
myTreeView.Nodes(2).Nodes(1).BackColor = Color.Yellow
' Configure the TreeView control for owner-draw.
myTreeView.DrawMode = TreeViewDrawMode.OwnerDrawText
' Add a handler for the MouseDown event so that a node can be
' selected by clicking the tag text as well as the node text.
AddHandler myTreeView.MouseDown, AddressOf myTreeView_MouseDown
' Initialize the form and add the TreeView control to it.
Me.ClientSize = New Size(292, 273)
Me.Controls.Add(myTreeView)
End Sub
注解
属性使用此 TreeView.DrawMode 枚举来指示 的节点或节点标签 TreeView 是所有者绘制的。 有关详细信息,请参阅 TreeView.DrawNode 事件。