当前位置: 首页>>代码示例>>C#>>正文


C# TreeView.LabelEdit属性代码示例

本文整理汇总了C#中System.Windows.Forms.TreeView.LabelEdit属性的典型用法代码示例。如果您正苦于以下问题:C# TreeView.LabelEdit属性的具体用法?C# TreeView.LabelEdit怎么用?C# TreeView.LabelEdit使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Windows.Forms.TreeView的用法示例。


在下文中一共展示了TreeView.LabelEdit属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: treeView1_MouseDown

/* Get the tree node under the mouse pointer and 
   save it in the mySelectedNode variable. */
private void treeView1_MouseDown(object sender, 
  System.Windows.Forms.MouseEventArgs e)
{
   mySelectedNode = treeView1.GetNodeAt(e.X, e.Y);
}

private void menuItem1_Click(object sender, System.EventArgs e)
{
   if (mySelectedNode != null && mySelectedNode.Parent != null)
   {
      treeView1.SelectedNode = mySelectedNode;
      treeView1.LabelEdit = true;
      if(!mySelectedNode.IsEditing)
      {
         mySelectedNode.BeginEdit();
      }
   }
   else
   {
      MessageBox.Show("No tree node selected or selected node is a root node.\n" + 
         "Editing of root nodes is not allowed.", "Invalid selection");
   }
}

private void treeView1_AfterLabelEdit(object sender, 
         System.Windows.Forms.NodeLabelEditEventArgs e)
{
   if (e.Label != null)
   {
     if(e.Label.Length > 0)
     {
        if (e.Label.IndexOfAny(new char[]{'@', '.', ',', '!'}) == -1)
        {
           // Stop editing without canceling the label change.
           e.Node.EndEdit(false);
        }
        else
        {
           /* Cancel the label edit action, inform the user, and 
              place the node in edit mode again. */
           e.CancelEdit = true;
           MessageBox.Show("Invalid tree node label.\n" + 
              "The invalid characters are: '@','.', ',', '!'", 
              "Node Label Edit");
           e.Node.BeginEdit();
        }
     }
     else
     {
        /* Cancel the label edit action, inform the user, and 
           place the node in edit mode again. */
        e.CancelEdit = true;
        MessageBox.Show("Invalid tree node label.\nThe label cannot be blank", 
           "Node Label Edit");
        e.Node.BeginEdit();
     }
   }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:60,代码来源:TreeView.LabelEdit

示例2: ImageList

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TreeView
{
  /// <summary>
  /// Summary description for TreeViewDemo.
  /// </summary>
  public class TreeViewDemo : System.Windows.Forms.Form
  {
    private System.Windows.Forms.TreeView treeView1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    ImageList il = new ImageList();
    public TreeViewDemo()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null) 
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
         this.treeView1 = new System.Windows.Forms.TreeView();
         this.SuspendLayout();
         // 
         // treeView1
         // 
         this.treeView1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right);
         this.treeView1.Font = new System.Drawing.Font("Courier New", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.treeView1.HotTracking = true;
         this.treeView1.ImageIndex = -1;
         this.treeView1.Indent = 30;
         this.treeView1.ItemHeight = 30;
         this.treeView1.LabelEdit = true;
         this.treeView1.Location = new System.Drawing.Point(8, 16);
         this.treeView1.Name = "treeView1";
         this.treeView1.SelectedImageIndex = -1;
         this.treeView1.Size = new System.Drawing.Size(360, 272);
         this.treeView1.TabIndex = 0;
         // 
         // TreeViewDemo
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(376, 309);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.treeView1});
         this.Name = "TreeViewDemo";
         this.Text = "TreeView Control";
         this.Load += new System.EventHandler(this.TreeViewDemo_Load);
         this.ResumeLayout(false);

      }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new TreeViewDemo());
    }

    private void TreeViewDemo_Load(object sender, System.EventArgs e)
    {
      // Select icons into the image list
      il.Images.Add(new Icon("KEY04.ICO"));
      il.Images.Add(new Icon("ARW06LT.ICO"));
      il.Images.Add(new Icon("LITENING.ICO"));
      il.Images.Add(new Icon("ARW06UP.ICO"));
      treeView1.ImageList = il ; 
  
      // Create the RootNode
      TreeNode rootNode = treeView1.Nodes.Add("USA");
      rootNode.ImageIndex =0 ;

      // Create the Child nodes for the root
      TreeNode states1 = rootNode.Nodes.Add("New York");
      states1.ImageIndex =1 ;
      TreeNode states2 = rootNode.Nodes.Add("Michigan");
      states2.ImageIndex =1 ;
      TreeNode states3 = rootNode.Nodes.Add("Wisconsin");
      states3.ImageIndex =1 ;
      TreeNode states4 = rootNode.Nodes.Add("California");
      states4.ImageIndex =1 ;

      // Create siblings nodes for the Child nodes 
      TreeNode child = states1.Nodes.Add("Rochester");
      child.ImageIndex = 2 ;
      child =states1.Nodes.Add("new York");
      child.ImageIndex = 2 ;
      child =states1.Nodes.Add("Albany");
      child.ImageIndex = 2 ;

      child = states2.Nodes.Add("Detroit");
      child.ImageIndex = 2 ;
      child =states2.Nodes.Add("Ann Arbor");
      child.ImageIndex = 2 ;
      child =states2.Nodes.Add("Lansing");
      child.ImageIndex = 2 ;

      child = states3.Nodes.Add("Milwaukee");
      child.ImageIndex = 2 ;
      child =states3.Nodes.Add("Madison");
      child.ImageIndex = 2 ;
      child =states3.Nodes.Add("La Cross");
      child.ImageIndex = 2 ;
    
      child = states4.Nodes.Add("Los Angeles");
      child.ImageIndex = 2 ;
      child =states4.Nodes.Add("San Fransisco");
      child.ImageIndex = 2 ;
      child =states4.Nodes.Add("San Diego");
      child.ImageIndex = 2 ;
    }
  }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:159,代码来源:TreeView.LabelEdit


注:本文中的System.Windows.Forms.TreeView.LabelEdit属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。