當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET TreeView.GetNodeAt方法代碼示例

本文整理匯總了VB.NET中System.Windows.Forms.TreeView.GetNodeAt方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET TreeView.GetNodeAt方法的具體用法?VB.NET TreeView.GetNodeAt怎麽用?VB.NET TreeView.GetNodeAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.TreeView的用法示例。


在下文中一共展示了TreeView.GetNodeAt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Not

' Get the tree node under the mouse pointer and
' save it in the mySelectedNode variable. 
Private Sub treeView1_MouseDown(sender As Object, _
  e As System.Windows.Forms.MouseEventArgs)
        
   mySelectedNode = treeView1.GetNodeAt(e.X, e.Y)
End Sub    
    
Private Sub menuItem1_Click(sender As Object, e As System.EventArgs)
   If Not (mySelectedNode Is Nothing) And _
     Not (mySelectedNode.Parent Is Nothing) Then
      treeView1.SelectedNode = mySelectedNode
      treeView1.LabelEdit = True
      If Not mySelectedNode.IsEditing Then
         mySelectedNode.BeginEdit()
      End If
   Else
      MessageBox.Show("No tree node selected or selected node is a root node." & _
        Microsoft.VisualBasic.ControlChars.Cr & _
        "Editing of root nodes is not allowed.", "Invalid selection")
   End If
End Sub    
    
Private Sub treeView1_AfterLabelEdit(sender As Object, _
  e As System.Windows.Forms.NodeLabelEditEventArgs)
   If Not (e.Label Is Nothing) Then
      If e.Label.Length > 0 Then
         If e.Label.IndexOfAny(New Char() {"@"c, "."c, ","c, "!"c}) = -1 Then
            ' 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." & _
              Microsoft.VisualBasic.ControlChars.Cr & _
              "The invalid characters are: '@','.', ',', '!'", _
              "Node Label Edit")
            e.Node.BeginEdit()
         End If
      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." & _
           Microsoft.VisualBasic.ControlChars.Cr & _
           "The label cannot be blank", "Node Label Edit")
           e.Node.BeginEdit()
      End If
   End If
End Sub
開發者ID:VB.NET開發者,項目名稱:System.Windows.Forms,代碼行數:51,代碼來源:TreeView.GetNodeAt

示例2: MainClass

' 導入命名空間
Imports System
Imports System.Collections
Imports System.Data

Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Drawing.Drawing2D
Imports System.IO

Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1

        Application.Run(form1)


    End Sub
End Class




Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents treeOne As System.Windows.Forms.TreeView
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents treeTwo As System.Windows.Forms.TreeView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.treeOne = New System.Windows.Forms.TreeView()
        Me.Splitter1 = New System.Windows.Forms.Splitter()
        Me.treeTwo = New System.Windows.Forms.TreeView()
        Me.SuspendLayout()
        '
        'treeOne
        '
        Me.treeOne.Dock = System.Windows.Forms.DockStyle.Left
        Me.treeOne.HideSelection = False
        Me.treeOne.ImageIndex = -1
        Me.treeOne.Location = New System.Drawing.Point(5, 5)
        Me.treeOne.Name = "treeOne"
        Me.treeOne.SelectedImageIndex = -1
        Me.treeOne.Size = New System.Drawing.Size(236, 351)
        Me.treeOne.TabIndex = 0
        '
        'Splitter1
        '
        Me.Splitter1.Location = New System.Drawing.Point(241, 5)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 351)
        Me.Splitter1.TabIndex = 2
        Me.Splitter1.TabStop = False
        '
        'treeTwo
        '
        Me.treeTwo.Dock = System.Windows.Forms.DockStyle.Fill
        Me.treeTwo.HideSelection = False
        Me.treeTwo.ImageIndex = -1
        Me.treeTwo.Location = New System.Drawing.Point(244, 5)
        Me.treeTwo.Name = "treeTwo"
        Me.treeTwo.SelectedImageIndex = -1
        Me.treeTwo.Size = New System.Drawing.Size(271, 351)
        Me.treeTwo.TabIndex = 3
        '
        'TreeViewExample
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(520, 366)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.treeTwo, Me.Splitter1, Me.treeOne})
        Me.DockPadding.Bottom = 10
        Me.DockPadding.Left = 5
        Me.DockPadding.Right = 5
        Me.DockPadding.Top = 5
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "TreeViewExample"
        Me.Text = "TreeView Example"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub TreeViewExample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim node As TreeNode

        node = treeOne.Nodes.Add("Node 1")
        node.Nodes.Add("Leap 1")
        node.Nodes.Add("Leap 2")
        node.Expand()

        node = treeTwo.Nodes.Add("Node 2")
        node.Nodes.Add("Leap 3")
        node.Nodes.Add("Leap 4")
        node.Expand()

        treeTwo.AllowDrop = True
        treeOne.AllowDrop = True

    End Sub

    Private Sub treeOne_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles treeOne.MouseDown, treeTwo.MouseDown
        Dim tree As TreeView = CType(sender, TreeView)

        Dim node As TreeNode
        node = tree.GetNodeAt(e.X, e.Y)
        tree.SelectedNode = node

        If Not node Is Nothing Then
            tree.DoDragDrop(node.Clone(), DragDropEffects.Copy)
        End If

    End Sub

    Private Sub treeTwo_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragOver, treeTwo.DragOver
        Dim tree As TreeView = CType(sender, TreeView)

        e.Effect = DragDropEffects.None

        If Not e.Data.GetData(GetType(TreeNode)) Is Nothing Then
            Dim pt As New Point(e.X, e.Y)
            pt = tree.PointToClient(pt)
            Dim node As TreeNode = tree.GetNodeAt(pt)
            If Not node Is Nothing Then
                e.Effect = DragDropEffects.Copy
                tree.SelectedNode = node
            End If

        End If

    End Sub

    Private Sub treeTwo_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragDrop, treeTwo.DragDrop
        Dim tree As TreeView = CType(sender, TreeView)
        Dim pt As New Point(e.X, e.Y)
        pt = tree.PointToClient(pt)

        Dim node As TreeNode = tree.GetNodeAt(pt)

        node.Nodes.Add(e.Data.GetData(GetType(TreeNode)))

        node.Expand()
    End Sub
End Class
開發者ID:VB程序員,項目名稱:System.Windows.Forms,代碼行數:174,代碼來源:TreeView.GetNodeAt


注:本文中的System.Windows.Forms.TreeView.GetNodeAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。