如何用代码给TreeView的节点添加样式?(ASP.NET)

如何用代码给TreeView的节点添加样式?(ASP.NET),第1张

恭喜你,楼上成功的把你忽悠了,那个是添加节点的方法

TreeView tv = new TreeView()

tv.NodeStyle 其实TreeView有NodeStyle属性的,你可以设置

//contextMenuStrip1与treeView1关联,在节点上单击右键就给该节点添加子节点,在空白地方单击右键,就添加根节点

using System

using System.Collections.Generic

using System.ComponentModel

using System.Data

using System.Drawing

using System.Text

using System.Windows.Forms

namespace WindowsApplication8

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent()

this.treeView1.LabelEdit = true

}

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)

{

if (e.Button == MouseButtons.Right)

{

this.treeView1.SelectedNode = e.Node

flag = true

contextMenuStrip1.Show(MousePosition)

}

}

bool flag = false

private void 添加节点ToolStripMenuItem_Click(object sender, EventArgs e)

{

TreeNode tn = new TreeNode()

if (flag)

{

this.treeView1.SelectedNode.Nodes.Add(tn)

this.treeView1.SelectedNode = tn

tn.BeginEdit()

flag = false

}

else

{

this.treeView1.Nodes.Add(tn)

this.treeView1.SelectedNode = tn

tn.BeginEdit()

flag = false

}

}

private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)

{

e.Node.Text = e.Label

}

private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)

{

if (!flag)

{

this.treeView1.SelectedNode = null

}

}

bool flag1 = false

private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)

{

flag1 = true

}

private void contextMenuStrip1_Closed(object sender, ToolStripDropDownClosedEventArgs e)

{

if (!flag1)

{

flag = false

}

else

{

flag1 = false

}

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11636857.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存