zy62/63_树状视图(TreeView);节点的设置程序;控件布局

1.树状视图重要属性和事件

ImageList:引用图片

Nodes:节点属性


2.完整程序理解树状视图

节点的设置程序:

private void treeViewBrowser_AfterSelect(object sender, TreeViewEventArgs e)
{
    string myDocPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    string myPicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
    string myMusPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
    switch (e.Node.Text)
    {
        case "Documents": System.Diagnostics.Process.Start(myDocPath); break;
        case "Music": System.Diagnostics.Process.Start(myMusPath); break;
        case "Pictures": System.Diagnostics.Process.Start(myPicPath); break;
    }
}

private void treeViewBrowser_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
    switch (e.Node.Text)
    {
        case "Microsoft Edge": System.Diagnostics.Process.Start("IExplore"); break;
        case "Notepad": System.Diagnostics.Process.Start("Notepad"); break;
        case "Calculator": System.Diagnostics.Process.Start("calc"); break;
    }
}

private void button1_Click(object sender, EventArgs e)
{
    TreeNode node1 = new TreeNode("Node1");
    node1.ImageIndex = 2;
    node1.SelectedImageIndex = 2;
    treeViewBrowser.Nodes.Add(node1);
    TreeNode node1a = new TreeNode("Node1a");
    node1a.ImageIndex = 5;
    node1a.SelectedImageIndex = 5;
    node1a.Nodes.Add(node1a);
}

private void button2_Click(object sender, EventArgs e)
{
    TreeNode node2a = new TreeNode("Node2a");
    node2a.ImageIndex = 6;
    node2a.SelectedImageIndex = 6;
    treeViewBrowser.SelectedNode.Nodes.Add(node2a);
}

3.控件布局

3.1锚定(Anchor)

锚定上下左右距离

3.2停靠(Dock)

停靠在上下左右中

private void button1_Click(object sender, EventArgs e)
{
    button1.SendToBack();
}

private void button2_Click(object sender, EventArgs e)
{
    button2.SendToBack();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值