本文整理汇总了VB.NET中System.Windows.Forms.ListBox.IndexFromPoint方法的典型用法代码示例。如果您正苦于以下问题:VB.NET ListBox.IndexFromPoint方法的具体用法?VB.NET ListBox.IndexFromPoint怎么用?VB.NET ListBox.IndexFromPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListBox 的用法示例。
在下文中一共展示了ListBox.IndexFromPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: New
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
richTextBox1.AllowDrop = True
End Sub
Private Sub listBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles listBox1.MouseDown
' Determines which item was selected.
Dim lb As ListBox = CType(sender, ListBox)
Dim pt As New Point(e.X, e.Y)
'Retrieve the item at the specified location within the ListBox.
Dim index As Integer = lb.IndexFromPoint(pt)
' Starts a drag-and-drop operation.
If index >= 0 Then
' Retrieve the selected item text to drag into the RichTextBox.
lb.DoDragDrop(lb.Items(index).ToString(), DragDropEffects.Copy)
End If
End Sub
Private Sub richTextBox1_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles richTextBox1.DragEnter
' If the data is text, copy the data to the RichTextBox control.
If e.Data.GetDataPresent("Text") Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub richTextBox1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles richTextBox1.DragDrop
' Paste the text into the RichTextBox where at selection location.
richTextBox1.SelectedText = e.Data.GetData("System.String", True).ToString()
End Sub
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:36,代码来源:ListBox.IndexFromPoint
示例2: MainClass
' 导入命名空间
Imports System.Drawing.Drawing2D
Imports System
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Math
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub
End Class
Public Class Form1
Private m_DragSource As ListBox = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
lstUnselected.AllowDrop = True
lstSelected.AllowDrop = True
' Add event handlers.
AddHandler lstUnselected.MouseDown, AddressOf List_MouseDown
AddHandler lstUnselected.DragOver, AddressOf List_DragOver
AddHandler lstUnselected.DragDrop, AddressOf List_DragDrop
AddHandler lstUnselected.DragLeave, AddressOf List_DragLeave
AddHandler lstSelected.MouseDown, AddressOf List_MouseDown
AddHandler lstSelected.DragOver, AddressOf List_DragOver
AddHandler lstSelected.DragDrop, AddressOf List_DragDrop
AddHandler lstSelected.DragLeave, AddressOf List_DragLeave
End Sub
Private Sub List_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs)
Dim this_list As ListBox = DirectCast(sender, ListBox)
this_list.SelectedIndex = this_list.IndexFromPoint(e.X, e.Y)
If this_list.SelectedIndex < 0 Then Exit Sub
m_DragSource = this_list
this_list.DoDragDrop(this_list.SelectedItem.ToString,DragDropEffects.Move)
m_DragSource = Nothing
End Sub
Private Sub List_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
If m_DragSource Is Nothing Then Exit Sub
e.Effect = DragDropEffects.Move
Dim this_list As ListBox = DirectCast(sender, ListBox)
Dim pt As Point = this_list.PointToClient(New Point(e.X, e.Y))
Dim drop_index As Integer = this_list.IndexFromPoint(pt.X, pt.Y)
this_list.SelectedIndex = drop_index
End Sub
Private Sub List_DragLeave(ByVal sender As Object, ByVal e As System.EventArgs)
Dim this_list As ListBox = DirectCast(sender, ListBox)
this_list.SelectedIndex = -1
End Sub
' Accept the drop.
Private Sub List_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs)
Dim this_list As ListBox = DirectCast(sender, ListBox)
MoveItem(e.Data.GetData(DataFormats.Text).ToString, _
m_DragSource, this_list, e.X, e.Y)
End Sub
' Move the value txt from drag_source to drop_target.
Private Sub MoveItem(ByVal txt As String, ByVal drag_source As ListBox, _
ByVal drop_target As ListBox, ByVal X As Integer, ByVal Y As Integer)
Dim drop_index As Integer = drop_target.SelectedIndex
If drop_index < 0 Then
drop_index = drop_target.Items.Add(txt)
Else
drop_target.Items.Insert(drop_target.SelectedIndex, txt)
End If
drop_target.SelectedIndex = drop_index
If drag_source Is drop_target Then
Dim target_index As Integer = drag_source.FindStringExact(txt)
If target_index = drop_index Then _
target_index = drag_source.FindStringExact(txt, target_index)
drag_source.Items.RemoveAt(target_index)
Else
drag_source.Items.Remove(txt)
End If
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Public Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
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.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.lstSelected = New System.Windows.Forms.ListBox
Me.lstUnselected = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(152, 0)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(144, 16)
Me.Label2.TabIndex = 11
Me.Label2.Text = "Right"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(144, 16)
Me.Label1.TabIndex = 10
Me.Label1.Text = "Left"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'lstSelected
'
Me.lstSelected.FormattingEnabled = True
Me.lstSelected.Items.AddRange(New Object() {"1", "2", "3", "4", "5", "6", "7", "8"})
Me.lstSelected.Location = New System.Drawing.Point(152, 16)
Me.lstSelected.Name = "lstSelected"
Me.lstSelected.Size = New System.Drawing.Size(144, 264)
Me.lstSelected.TabIndex = 9
'
'lstUnselected
'
Me.lstUnselected.FormattingEnabled = True
Me.lstUnselected.Items.AddRange(New Object() {"A", "B", "C", "D", "E", "F", "G", "H"})
Me.lstUnselected.Location = New System.Drawing.Point(0, 16)
Me.lstUnselected.Name = "lstUnselected"
Me.lstUnselected.Size = New System.Drawing.Size(144, 264)
Me.lstUnselected.TabIndex = 8
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(297, 281)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.lstSelected)
Me.Controls.Add(Me.lstUnselected)
Me.Name = "Form1"
Me.Text = "DragBetweenListBoxes"
Me.ResumeLayout(False)
End Sub
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents lstSelected As System.Windows.Forms.ListBox
Friend WithEvents lstUnselected As System.Windows.Forms.ListBox
End Class
开发者ID:VB程序员,项目名称:System.Windows.Forms,代码行数:178,代码来源:ListBox.IndexFromPoint
注:本文中的System.Windows.Forms.ListBox.IndexFromPoint方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论