[C#][控件]高级控件

2022-05-07 18:31:55 浏览数 (1)

高级控件

1. TreeView

代码语言:javascript复制
//1.1 添加节点
TreeNode tn1 = treeView1.Nodes.Add("名称");
TreeNode tn2 = treeView1.Nodes.Add("类别");

TreeNode subA_tn1 = new TreeNode("A");
TreeNode subB_tn1 = new TreeNode("B");
TreeNode subC_tn1 = new TreeNode("C");
tn1.Nodes.Add(subA_tn1);
tn1.Nodes.Add(subB_tn1);
tn1.Nodes.Add(subC_tn1);


TreeNode sub1_tn2 = new TreeNode("1");
TreeNode sub2_tn2 = new TreeNode("2");
TreeNode sub3_tn2 = new TreeNode("3");
tn2.Nodes.Add(sub1_tn2);
tn2.Nodes.Add(sub2_tn2);
tn2.Nodes.Add(sub3_tn2);

//1.2 移除节点
private void button1_Click(object sender, EventArgs e)
{
	treeView1.Nodes.Remove(treeView1.SelectedNode);
}

//1.3 为节点设置图标
imageList1.Images.Add(Image.FromFile("图片地址1"));
imageList1.Images.Add(Image.FromFile("图片地址2"));
treeView1.ImageList = imageList1;
treeView1.ImageIndex = 0;
treeView1.SelectedImageIndex = 1;

2. ProgressBar

代码语言:javascript复制
progressBar1.Value = 0;
progressBar1.Minimum = 0;
progressBar1.Maximum = 500;
progressBar1.Step = 1;
for(int i=0; i<=500; i  )
{
	progressBar1.PerformStep();
}

0 人点赞