TreeView.BeforeLabelEdit イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TreeView.BeforeLabelEdit イベントの意味・解説 

TreeView.BeforeLabelEdit イベント

ツリー ノードラベル テキスト編集される前に発生します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event BeforeLabelEdit As
 NodeLabelEditEventHandler
Dim instance As TreeView
Dim handler As NodeLabelEditEventHandler

AddHandler instance.BeforeLabelEdit, handler
public event NodeLabelEditEventHandler BeforeLabelEdit
public:
event NodeLabelEditEventHandler^ BeforeLabelEdit {
    void add (NodeLabelEditEventHandler^ value);
    void remove (NodeLabelEditEventHandler^ value);
}
/** @event */
public void add_BeforeLabelEdit (NodeLabelEditEventHandler
 value)

/** @event */
public void remove_BeforeLabelEdit (NodeLabelEditEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

BeforeLabelEdit、AfterSelect、および TopNode の各メンバ使用方法次のコード例示します。この例を実行するには、TreeView1 という名前の TreeView コントロール配置されているフォームに、次のコード貼り付けます。そして、フォームコンストラクタまたは Load メソッドInitializeTreeView メソッド呼び出します。

    Private Sub InitializeTreeView()

        ' Construct the TreeView object.
        Me.TreeView1 = New System.Windows.Forms.TreeView

        ' Set dock, location, size name, and tab order
        ' values for the TreeView object.

        With TreeView1
            .Dock = System.Windows.Forms.DockStyle.Left
            .Location = New System.Drawing.Point(0, 0)
            .Name = "TreeView1"
            .Size = New System.Drawing.Size(152, 266)
            .TabIndex = 1
        End With

        ' Set the LabelEdit property to true to allow the 
        ' user to edit the TreeNode text.
        Me.TreeView1.LabelEdit = True

        ' Declare and create objects needed to populate 
        ' the TreeView.
        Dim file, files(), filePath As String
        files = New String() {"bigPresentation.ppt",
 "myFinances.xls", _
            "myResume.doc"}
        filePath = "c:\myFiles"
        Dim nodes As New
 System.Collections.ArrayList

        ' Create a node for each file, setting the Text property to
 the 
        ' file's name and the Tag property to file's fully-qualified
 name.
        For Each file In
 files
            Dim node As New
 TreeNode(file)
            node.Tag = filePath & "\" & file
            nodes.Add(node)
        Next

        ' Create a new node named topNode and add the ArrayList of 
        ' nodes to topNode.
        Dim topNode As New
 TreeNode("myFiles", _
            nodes.ToArray(GetType(TreeNode)))

        topNode.Tag = filePath

        ' Add topNode to the TreeView.
        TreeView1.Nodes.Add(topNode)

        ' Add the TreeView to the form.
        Me.Controls.Add(TreeView1)
    End Sub

    Private Sub TreeView1_BeforeLabelEdit(ByVal
 sender As Object, _
        ByVal e As NodeLabelEditEventArgs)
 Handles TreeView1.BeforeLabelEdit

        ' Determine whether the user has selected the top node. If so
,
        ' change the LabelEdit property to false so the user cannot
        ' edit this label.  
        If (e.Node Is TreeView1.TopNode) Then

            TreeView1.LabelEdit = False
            MessageBox.Show("You are not allowed to edit the top
 node")
        End If

        ' Set the LabelEdit property to true again.
        TreeView1.LabelEdit = True
    End Sub
<br /><span space="preserve">...</span><br
 />    ' Handle the After_Select event.
    Private Sub TreeView1_AfterSelect(ByVal
 sender As System.Object, _
        ByVal e As System.Windows.Forms.TreeViewEventArgs)
 _
            Handles TreeView1.AfterSelect

        ' Vary the response depending on which TreeViewAction
        ' triggered the event. 
        Select Case (e.Action)
            Case TreeViewAction.ByKeyboard
                MessageBox.Show("You like the keyboard!")
            Case TreeViewAction.ByMouse
                MessageBox.Show("You like the mouse!")
        End Select
    End Sub
    private void InitializeTreeView()
    {

        // Construct the TreeView object.
        this.TreeView1 = new System.Windows.Forms.TreeView();

        // Set dock, location, size name, and tab order
        // values for the TreeView object.
        TreeView1.Dock = System.Windows.Forms.DockStyle.Left;
        TreeView1.Location = new System.Drawing.Point(0, 0);
        TreeView1.Name = "TreeView1";
        TreeView1.Size = new System.Drawing.Size(152, 266);
        TreeView1.TabIndex = 1;
        
        // Associate the event-handling methods with the
        // BeforeLabeEdit and the AfterSelect events.
        TreeView1.BeforeLabelEdit += 
            new NodeLabelEditEventHandler(TreeView1_BeforeLabelEdit);
        TreeView1.AfterSelect += 
            new TreeViewEventHandler(TreeView1_AfterSelect);

        // Set the LabelEdit property to true to allow the 
        // user to edit the TreeNode text.
        this.TreeView1.LabelEdit = true;

        // Declare and create objects needed to populate 
        // the TreeView.
        string[] files = new string[]{"bigPresentation.ppt",
 
            "myFinances.xls", "myResume.doc"};; 
        string filePath = "c:\\myFiles";
        System.Collections.ArrayList nodes = 
            new System.Collections.ArrayList();

        // Create a node for each file, setting the Text property to
 the 
        // file's name and the Tag property to file's fully-qualified
 name.
        foreach ( string file in
 files )
        {
            TreeNode node = new TreeNode(file);
            node.Tag = filePath+"\\"+file;
            nodes.Add(node);
        }

        TreeNode[] treeNodes = new TreeNode[nodes.Count];
        nodes.CopyTo(treeNodes);

        // Create a new node named topNode and add the ArrayList of
 
        // nodes to topNode.
        TreeNode topNode = new TreeNode("myFiles", 
 treeNodes);
        topNode.Tag = filePath;

        // Add topNode to the TreeView.
        TreeView1.Nodes.Add(topNode);

        // Add the TreeView to the form.
        this.Controls.Add(TreeView1);
    }

    private void TreeView1_BeforeLabelEdit(object
 sender, 
        NodeLabelEditEventArgs e)
    {

        // Determine whether the user has selected the top node. If
 so,
        // change the LabelEdit property to false so the user cannot
        // edit this label.  
        if (e.Node == TreeView1.TopNode)

        {
            TreeView1.LabelEdit = false;
            MessageBox.Show("You are not allowed to edit the top node");
        }
        // Set the LabelEdit property to true again.
        TreeView1.LabelEdit = true;
    }
<br /><span space="preserve">...</span><br /> 
   // Handle the After_Select event.
    private void TreeView1_AfterSelect(System.Object
 sender, 
        System.Windows.Forms.TreeViewEventArgs e)
    {

        // Vary the response depending on which TreeViewAction
        // triggered the event. 
        switch((e.Action))
        {
            case TreeViewAction.ByKeyboard:
                MessageBox.Show("You like the keyboard!");
                break;
            case TreeViewAction.ByMouse:
                MessageBox.Show("You like the mouse!");
                break;
        }
    }
private:
   void InitializeTreeView()
   {
      
      // Construct the TreeView object.
      this->TreeView1 = gcnew System::Windows::Forms::TreeView;
      
      // Set dock, location, size name, and tab order
      // values for the TreeView object.
      TreeView1->Dock = System::Windows::Forms::DockStyle::Left;
      TreeView1->Location = System::Drawing::Point( 0, 0 );
      TreeView1->Name = "TreeView1";
      TreeView1->Size = System::Drawing::Size( 152, 266 );
      TreeView1->TabIndex = 1;
      
      // Associate the event-handling methods with the
      // BeforeLabeEdit and the AfterSelect events.
      TreeView1->BeforeLabelEdit += gcnew NodeLabelEditEventHandler( this,
 &Form1::TreeView1_BeforeLabelEdit );
      TreeView1->AfterSelect += gcnew TreeViewEventHandler( this,
 &Form1::TreeView1_AfterSelect );
      
      // Set the LabelEdit property to true to allow the 
      // user to edit the TreeNode text.
      this->TreeView1->LabelEdit = true;
      
      // Declare and create objects needed to populate 
      // the TreeView.
      array<String^>^files = {"bigPresentation.ppt","myFinances.xls"
,"myResume.doc"};
      ;
      String^ filePath = "c:\\myFiles";
      System::Collections::ArrayList^ nodes = gcnew System::Collections::ArrayList;
      
      // Create a node for each file, setting the Text property to the
 
      // file's name and the Tag property to file's fully-qualified
 name.
      System::Collections::IEnumerator^ myEnum = files->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         String^ file = safe_cast<String^>(myEnum->Current);
         TreeNode^ node = gcnew TreeNode( file );
         node->Tag = String::Concat( filePath, "\\", file );
         nodes->Add( node );
      }

      array<TreeNode^>^treeNodes = gcnew array<TreeNode^>(nodes->Count);
      nodes->CopyTo( treeNodes );
      
      // Create a new node named topNode and add the ArrayList of 
      // nodes to topNode.
      TreeNode^ topNode = gcnew TreeNode( "myFiles",treeNodes );
      topNode->Tag = filePath;
      
      // Add topNode to the TreeView.
      TreeView1->Nodes->Add( topNode );
      
      // Add the TreeView to the form.
      this->Controls->Add( TreeView1 );
   }

   void TreeView1_BeforeLabelEdit( Object^ /*sender*/, NodeLabelEditEventArgs^
 e )
   {
      
      // Determine whether the user has selected the top node. If so
,
      // change the LabelEdit property to false so the user cannot
      // edit this label.  
      if ( e->Node == TreeView1->TopNode )
      {
         TreeView1->LabelEdit = false;
         MessageBox::Show( "You are not allowed to edit the top node" );
      }

      
      // Set the LabelEdit property to true again.
      TreeView1->LabelEdit = true;
   }
<br /><span space="preserve">...</span><br />private:
   // Handle the After_Select event.
   void TreeView1_AfterSelect( System::Object^ /*sender*/, System::Windows::Forms::TreeViewEventArgs^
 e )
   {
      
      // Vary the response depending on which TreeViewAction
      // triggered the event. 
      switch ( (e->Action) )
      {
         case TreeViewAction::ByKeyboard:
            MessageBox::Show( "You like the keyboard!" );
            break;

         case TreeViewAction::ByMouse:
            MessageBox::Show( "You like the mouse!" );
            break;
      }
   }
    private void InitializeTreeView()
    {
        // Construct the TreeView object.
        this.treeView1 = new System.Windows.Forms.TreeView();
        // Set dock, location, size name, and tab order
        // values for the TreeView object.
        treeView1.set_Dock(System.Windows.Forms.DockStyle.Left);
        treeView1.set_Location(new System.Drawing.Point(0, 0));
        treeView1.set_Name("TreeView1");
        treeView1.set_Size(new System.Drawing.Size(152, 266));
        treeView1.set_TabIndex(1);
        // Associate the event-handling methods with the
        // BeforeLabeEdit and the AfterSelect events.
        treeView1.add_BeforeLabelEdit(
            new NodeLabelEditEventHandler(treeView1_BeforeLabelEdit));
        treeView1.add_AfterSelect(new TreeViewEventHandler(
            treeView1_AfterSelect));
        // Set the LabelEdit property to true to allow the 
        // user to edit the TreeNode text.
        this.treeView1.set_LabelEdit(true);
        // Declare and create objects needed to populate 
        // the TreeView.
        String files[] = new String[] { "bigPresentation.ppt",
 "myFinances.xls",
            "myResume.doc" };
        String filePath = "c:\\myFiles";
        System.Collections.ArrayList nodes = new System.Collections.ArrayList();
        // Create a node for each file, setting the Text property to
 the 
        // file's name and the Tag property to file's fully-qualified
 name.
        for (int iCtr = 0; iCtr < files.length;
 iCtr++) {
            String file = files[iCtr];
            TreeNode node = new TreeNode(file);
            node.set_Tag(filePath + "\\" + file);
            nodes.Add(node);
        }

        TreeNode treeNodes[] = new TreeNode[nodes.get_Count()];
        nodes.CopyTo(treeNodes);
        // Create a new node named topNode and add the ArrayList of
 
        // nodes to topNode.
        TreeNode topNode = new TreeNode("myFiles", treeNodes);
        topNode.set_Tag(filePath);
        // Add topNode to the TreeView.
        treeView1.get_Nodes().Add(topNode);
        // Add the TreeView to the form.
        this.get_Controls().Add(treeView1);
    } //InitializeTreeView

    private void treeView1_BeforeLabelEdit(Object
 sender,
        NodeLabelEditEventArgs e)
    {
        // Determine whether the user has selected the top node. If
 so,
        // change the LabelEdit property to false so the user cannot
        // edit this label.  
        if (e.get_Node().Equals(treeView1.get_TopNode())) {
            treeView1.set_LabelEdit(false);
            MessageBox.Show("You are not allowed to edit the top node");
        }
        // Set the LabelEdit property to true again.
        treeView1.set_LabelEdit(true);
    } //treeView1_BeforeLabelEdit
<br /><span space="preserve">...</span><br /> 
   // Handle the After_Select event.
    private void treeView1_AfterSelect(Object
 sender,
        System.Windows.Forms.TreeViewEventArgs e)
    {
        // Vary the response depending on which TreeViewAction
        // triggered the event. 
        switch (e.get_Action()) {
            case TreeViewAction.ByKeyboard:
                MessageBox.Show("You like the keyboard!");
                break;
            case TreeViewAction.ByMouse:
                MessageBox.Show("You like the mouse!");
                break;
        }
    } //treeView1_AfterSelect
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeView クラス
TreeView メンバ
System.Windows.Forms 名前空間
OnBeforeLabelEdit
TreeView.AfterLabelEdit イベント
OnAfterLabelEdit



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

TreeView.BeforeLabelEdit イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeView.BeforeLabelEdit イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS