vb给listview 编写双击事件

PrivateSubLabel1_Click(IndexAsInteger)SelectCaseIndexCase0Picture1.Picture=LoadPictur... Private Sub Label1_Click(Index As Integer)
Select Case Index
Case 0

Picture1.Picture = LoadPicture("")
a = ExtractIcon(App.hInstance, "D:\盛大网络\冒险岛online\maplestory.exe", 0)
a = DrawIcon(Picture1.hdc, 0, 0, a)
ImageList1.ListImages.Add 1, , Picture1.Image
ListView1.Icons = ImageList1
ListView1.ListItems.Add 1, , "冒险岛online", 1
'=======================分隔线=========================
Picture1.Picture = LoadPicture("")
a = ExtractIcon(App.hInstance, "D:\ZSNESW\运行游戏.exe", 0)
a = DrawIcon(Picture1.hdc, 0, 0, a)
ImageList1.ListImages.Add 2, , Picture1.Image
ListView1.ListItems.Add 2, , "超级玛丽", 2
'=======================分隔线=========================
Picture1.Picture = LoadPicture("")
a = ExtractIcon(App.hInstance, "D:\机械迷城\machinarium.exe", 0)
a = DrawIcon(Picture1.hdc, 0, 0, a)
ImageList1.ListImages.Add 3, , Picture1.Image
ListView1.ListItems.Add 3, , "机械迷城", 3
'=======================分隔线=========================
Picture1.Picture = LoadPicture("")
a = ExtractIcon(App.hInstance, "D:\Plants vs. Zombies\PlantsVsZombies.exe", 0)
a = DrawIcon(Picture1.hdc, 0, 0, a)
ImageList1.ListImages.Add 4, , Picture1.Image
ListView1.ListItems.Add 4, , "植物大战僵尸", 4
'=======================分隔线=========================
Picture1.Picture = LoadPicture("")
a = ExtractIcon(App.hInstance, "D:\Ballance\Startup.exe", 0)
a = DrawIcon(Picture1.hdc, 0, 0, a)
ImageList1.ListImages.Add 5, , Picture1.Image
ListView1.ListItems.Add 5, , "平衡球", 5
'=======================分隔线=========================
Picture1.Picture = LoadPicture("")
a = ExtractIcon(App.hInstance, "D:\新建文件夹\World of Goo V1.4\WorldOfGoo.exe", 0)
a = DrawIcon(Picture1.hdc, 0, 0, a)
ImageList1.ListImages.Add 6, , Picture1.Image
ListView1.ListItems.Add 6, , "粘粘世界", 6
End Select
End Sub
然后运行以后是这样
如何实现在 双击冒险岛那个图标时 运行冒险岛
双击其他图标 运行其他游戏
展开
 我来答
苑永修千月
2020-05-03 · TA获得超过3.7万个赞
知道大有可为答主
回答量:1.4万
采纳率:25%
帮助的人:964万
展开全部
Private
Sub
ListView1_dblclick()
if
ListView1.SelectedItem.Text
="冒险岛online",
"
End
Sub
Private
Sub
ListView1_dblclick()
If
ListView1.SelectedItem.Text
=
"冒险岛online"
Then
Shell
"D:\盛大网络\冒险岛online\maplestory.exe"
If
ListView1.SelectedItem.Text
=
"超级玛丽"
Then
Shell
"D:\ZSNESW\运行游戏.exe"
If
ListView1.SelectedItem.Text
=
"机械迷城"
Then
Shell
"D:\机械迷城\machinarium.exe"
If
ListView1.SelectedItem.Text
=
"植物大战僵尸"
Then
Shell
"D:\Plants
vs.
Zombies\PlantsVsZombies.exe"
If
ListView1.SelectedItem.Text
=
"平衡球"
Then
Shell
"D:\Ballance\Startup.exe"
If
ListView1.SelectedItem.Text
=
"粘粘世界"
Then
Shell
"D:\新建文件夹\World
of
Goo
V1.4\WorldOfGoo.exe"
End
Sub
cjsworld
2010-01-06 · TA获得超过151个赞
知道小有建树答主
回答量:115
采纳率:0%
帮助的人:137万
展开全部
你的加载item的过程太累赘。不习惯用循环?那你要加载更多的item怎么办?
建议你将信息存在文件或注册表中,然后用个循环读取并加载。这样以后也好修改。

帮你修改了下,将路径按以下格式存为txt文件。

冒险岛online
D:\盛大网络\冒险岛online\maplestory.exe
超级玛丽
D:\ZSNESW\运行游戏.exe
机械迷城
D:\机械迷城\machinarium.exe
植物大战僵尸
D:\Plants vs. Zombies\PlantsVsZombies.exe
平衡球
D:\Ballance\Startup.exe
粘粘世界
D:\新建文件夹\World of Goo V1.4\WorldOfGoo.exe

Private Sub Label1_Click(Index As Integer)
Select Case Index
Case 0
LoadData ("Games.txt")
Case 1
LoadData ("Tools.txt")
Case 2
...
End Select
End Sub

Private Sub LoadData(TxtFile As String)
Dim str As String, Data() As String
Dim Names() As String, Paths() As String
Dim i As Long, k As Long

'打开文件,读取内容
Open TxtFile For Binary As #1
str = Input(LOF(1), #1)
Close #1

Data() = Split(str, vbCrLf)
ReDim Names(0 To Int(UBound(Data) / 2))
ReDim Paths(0 To Int(UBound(Data) / 2))

k = 0
For i = 0 To UBound(Data) Step 2
'确保不为空
If Len(Data(i)) <> 0 And Len(Data(i + 1)) <> 0 Then
Names(k) = Data(i)
Paths(k) = Data(i + 1)

'添加图标
Dim a
Picture1.Picture = LoadPicture("")
a = ExtractIcon(App.hInstance, Paths(k), 0)
a = DrawIcon(Picture1.hdc, 0, 0, a)
ImageList1.ListImages.Add , , Picture1.Image

'添加项目,利用key属性储存路径数据
ListView1.ListItems.Add , Paths(k), Names(k), k + 1

k = k + 1

End If
Next i
End Sub

'双击
Private Sub ListView1_DblClick()
'判断是否点击到item
If Not ListView1.SelectedItem Is Nothing Then
Shell ListView1.SelectedItem.Key
End If
End Sub

'为了让Listview在没点到item时失去焦点
'否则点空白时selectitem不为空
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Not ListView1.HitTest(x, y) Is ListView1.SelectedItem Then
Set ListView1.SelectedItem = Nothing
End If
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
evening2009
2010-01-02 · 超过34用户采纳过TA的回答
知道答主
回答量:115
采纳率:0%
帮助的人:0
展开全部
关注
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式