TreeView.DrawMode 属性的

None.gif TreeView.DrawMode 属性的C#例子
None.gif
None.gif
None.gif下面的代码示例演示如何使用所有者描述来自定义 TreeView 控件。此示例中的 TreeView 控件在标准节点标签旁边显示可选的节点标记。使用 TreeNode.Tag 属性指定节点标记。TreeView 控件也使用自定义颜色,包括自定义突出显示颜色。
None.gif
None.gifview plaincopy to clipboardprint
?
None.gif
public  TreeViewOwnerDraw()   
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {   
InBlock.gif    
// Create and initialize the TreeView control.   
InBlock.gif
    myTreeView = new TreeView();   
InBlock.gif    myTreeView.Dock 
= DockStyle.Fill;   
InBlock.gif    myTreeView.BackColor 
= Color.Tan;   
InBlock.gif    myTreeView.CheckBoxes 
= true;   
InBlock.gif  
InBlock.gif    
// Add nodes to the TreeView control.   
InBlock.gif
    TreeNode node;   
InBlock.gif    
for (int x = 1; x < 4++x)   
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{   
InBlock.gif        
// Add a root node to the TreeView control.   
InBlock.gif
        node = myTreeView.Nodes.Add(String.Format("Task {0}", x));   
InBlock.gif        
for (int y = 1; y < 4++y)   
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{   
InBlock.gif            
// Add a child node to the root node.   
InBlock.gif
            node.Nodes.Add(String.Format("Subtask {0}", y));   
ExpandedSubBlockEnd.gif        }
   
ExpandedSubBlockEnd.gif    }
   
InBlock.gif    myTreeView.ExpandAll();   
InBlock.gif  
InBlock.gif    
// Add tags containing alert messages to a few nodes    
InBlock.gif    
// and set the node background color to highlight them.   
InBlock.gif
    myTreeView.Nodes[1].Nodes[0].Tag = "urgent!";   
InBlock.gif    myTreeView.Nodes[
1].Nodes[0].BackColor = Color.Yellow;   
InBlock.gif    myTreeView.SelectedNode 
= myTreeView.Nodes[1].Nodes[0];   
InBlock.gif    myTreeView.Nodes[
2].Nodes[1].Tag = "urgent!";   
InBlock.gif    myTreeView.Nodes[
2].Nodes[1].BackColor = Color.Yellow;   
InBlock.gif  
InBlock.gif    
// Configure the TreeView control for owner-draw and add   
InBlock.gif    
// a handler for the DrawNode event.   
InBlock.gif
    myTreeView.DrawMode = TreeViewDrawMode.OwnerDrawText;   
InBlock.gif    myTreeView.DrawNode 
+=    
InBlock.gif        
new DrawTreeNodeEventHandler(myTreeView_DrawNode);   
InBlock.gif  
InBlock.gif    
// Add a handler for the MouseDown event so that a node can be    
InBlock.gif    
// selected by clicking the tag text as well as the node text.   
InBlock.gif
    myTreeView.MouseDown += new MouseEventHandler(myTreeView_MouseDown);   
InBlock.gif  
InBlock.gif    
// Initialize the form and add the TreeView control to it.   
InBlock.gif
    this.ClientSize = new Size(292273);   
InBlock.gif    
this.Controls.Add(myTreeView);   
ExpandedBlockEnd.gif}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值