winform 中 怎样点击treeview节点 对应节点变色?

itliyi 2009-04-01 03:48:40
如题
...全文
376 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
itliyi 2009-04-03
  • 打赏
  • 举报
回复
不是
zgke 2009-04-02
  • 打赏
  • 举报
回复

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeView _TreeView =(TreeView)sender;
Control _SetLabel =_TreeView.Controls["SelectLab"];
if(_SetLabel==null)
{
Label _Label =new Label();
_Label.Name = "SelectLab";
_Label.AutoSize=false;
_Label.BackColor=Color.Yellow;
_Label.ForeColor=Color.Red;
_Label.Font = _TreeView.Font;
_TreeView.Controls.Add(_Label);
_SetLabel=_Label;
}
_SetLabel.Size=new Size(e.Node.Bounds.Width+5,e.Node.Bounds.Height);
_SetLabel.Location = new Point(e.Node.Bounds.X, e.Node.Bounds.Y);
_SetLabel.Text = e.Node.Text;
}
不知道你要的是不是这个效果
itliyi 2009-04-02
  • 打赏
  • 举报
回复
不行 点击下一个节点后才出现变色
messi_yang 2009-04-02
  • 打赏
  • 举报
回复
單擊事件~~
點擊出現變色~!
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
e.Node.ForeColor = Color.Red;
}
或是其他的顏色 你自己設置
itliyi 2009-04-02
  • 打赏
  • 举报
回复
h_w_king
怎样设置节点不被选中?
levinstong 2009-04-02
  • 打赏
  • 举报
回复
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
e.Node.ForeColor = Color.Red;
this.treeView1.Refresh();
}
}
}
h_w_king 2009-04-02
  • 打赏
  • 举报
回复
一般情况下,点击treeview节点, 节点呈选中状态.是蓝底白字.
你可以设置该treeview的节点不被选中.
itliyi 2009-04-02
  • 打赏
  • 举报
回复
还是不行啊 ,是不是也要改下背景?
h_w_king 2009-04-02
  • 打赏
  • 举报
回复
写错了,是
 this.treeView1.Refresh();
h_w_king 2009-04-02
  • 打赏
  • 举报
回复
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
e.Node.ForeColor = Color.Red;
this.Refresh();
}
itliyi 2009-04-02
  • 打赏
  • 举报
回复
但是要点击下一个节点效果才会出来?怎么解决?
jwdream2008 2009-04-01
  • 打赏
  • 举报
回复
 
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
e.Node.ForeColor = Color.Red;
}

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧