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();
}