如何在单击事件中运行与双击事件相同的代码? [英] How to run same code in click event as the double click event?

查看:27
本文介绍了如何在单击事件中运行与双击事件相同的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ListBox 中有 4 个项目,每个项目在被点击时都会执行特定的操作.

I have 4 items in a ListBox and each item does a specific thing when it gets clicked on.

但我也希望双击事件和点击事件做同样的事情.

But I also want the double click event to do the same thing as the click event.

我可以将单击事件中的所有代码复制并粘贴到双击事件中,但是随后您有大量代码挤在代码页中做同样的事情.那么该怎么办呢?

I can copy and paste all code from click event into double click event, but then you have lots of code crowding the code page doing the same thing. So what to do about this?

示例:

Private Sub listBox1_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) _
    Handles listBox1.DoubleClick

  if listbox1.doubleclick then do the same thing in listbox1.clickevent
  end if

End Sub

推荐答案

尝试以下代码!

Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click

    ListBox1_DoubleClick(sender, e)

End Sub

Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
    MsgBox(ListBox1.Items.Count)
End Sub

这篇关于如何在单击事件中运行与双击事件相同的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆