编程教程
您现在的位置: 中国个人站长站 >> 网络编程 >> ASP.NET教程 >> 教程正文 双击treeView的节点时使不展开不折叠子节点
推荐位

双击treeView的节点时使不展开不折叠子节点

中国个人站长站 ASP.NET教程 点击数: 更新时间:2007-7-9 21:05:00
Node("节点7")})})})}),
                      new System.Windows.Forms.TreeNode("节点2", new System.Windows.Forms.TreeNode[] {
                                           new System.Windows.Forms.TreeNode("节点0")}),
                      new System.Windows.Forms.TreeNode("节点3")});
   this.treeView1.SelectedImageIndex = -1;
   this.treeView1.Size = new System.Drawing.Size(216, 232);
   this.treeView1.TabIndex = 0;
   this.treeView1.Click += new System.EventHandler(this.treeView1_Click);
   this.treeView1.BeforeCollapse += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeView1_BeforeCollapse);
   this.treeView1.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeView1_BeforeExpand);
   //
   // Form1
   //

   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(256, 266);
   this.Controls.Add(this.treeView1);
   this.Name = "Form1";
   this.Text = "Form1";
   this.ResumeLayout(false);
  }
  #endregion
  /// <summary>
  ///
应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }
  private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
  {
   string path = null;
   TreeNode node = this.treeView1.SelectedNode;
   if (node != null)
   {
    path = node.Text;
    while (node.Parent != null )
    {
     node = node.Parent;
     path = node.Text + "\\"+ path;
    }
   }
  }
  private bool tmpBool;//用来决定是否打开或关闭树的节点
  private void treeView1_Click(object sender, System.EventArgs e)
  {
   object tmpObj = this.treeView1.GetNodeAt(this.treeView1.PointToClient(Cursor.Position));
   if (tmpObj!=null)
   {
    if ((tmpObj as TreeNode).Bounds.Contains(this.treeView1.PointToClient(Cursor.Position)))
    {
     tmpBool = true;
    }
   }
  }
  private void treeView1_BeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
  {
   if (tmpBool)
   {
    e.Cancel = tmpBool;
   }
   tmpBool = false;
  }
  private void treeView1_BeforeCollapse(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
  {
   if (tmpBool)
   {
    e.Cancel = tmpBool;
   }
   tmpBool = false;
  }
 }
}

上一页  [1] [2] 

教程录入:swh    责任编辑:swh 
个人站长站与你风雨同舟!
本站所提供的资源均来源于互联网,如有侵权行为,请与本站管理员联系,我们会第一时间删除!
·如果您发现《双击treeView的节点时使不展开不折叠子节点》文章有错误,也请通知我们修改!
联系邮箱chinageren#126.com,谢谢支持!
站内搜索:
广告服务 | 友情链接 | 联系我们 | 免责声明 | 用户留言 | 网站导航
版权所有:中国个人站长站 2007-2008 未经授权禁止复制或建立镜像 客服QQ号:112731235
copyright © 2007-2008 www.ChinaGeRen.com online services. all rights reserved. 苏ICP备05000059号