⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在listbox中获取鼠标下的项目.frm

📁 个人VB学习源码精选,自己学习时的一些编程小程序,希望对大家有帮助
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "监测鼠标所在位置的选项"
   ClientHeight    =   3390
   ClientLeft      =   1515
   ClientTop       =   1575
   ClientWidth     =   4020
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   3390
   ScaleWidth      =   4020
   Begin VB.TextBox Text1 
      Height          =   270
      Left            =   480
      TabIndex        =   1
      Top             =   2880
      Width           =   3255
   End
   Begin VB.ListBox List1 
      Height          =   1425
      ItemData        =   "在ListBox中获取鼠标下的项目.frx":0000
      Left            =   480
      List            =   "在ListBox中获取鼠标下的项目.frx":0184
      TabIndex        =   0
      Top             =   600
      Width           =   3255
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "鼠标底下的选项是"
      Height          =   195
      Left            =   240
      TabIndex        =   3
      Top             =   2520
      Width           =   1440
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "请将鼠标移到ListBox之中"
      Height          =   195
      Left            =   240
      TabIndex        =   2
      Top             =   240
      Width           =   1950
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim pos As Long, idx As Long
    
    pos = X / Screen.TwipsPerPixelX + Y / Screen.TwipsPerPixelY * 65536
    idx = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0, ByVal pos)
    
    If idx < 65536 Then Text1.Text = List1.List(idx)
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -