当前位置: 首页>>代码示例>>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;未经允许,请勿转载。