The following code example demonstrates how to use the owner description to customize the Treeview control. The Treeview control in this example displays an optional node label next to the standard node label. Use the treenode. Tag attribute to specify the node tag. The Treeview control also uses custom colors, including custom highlight colors.
View plaincopy to clipboardprint?
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 );
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.