VB.NET 中的组合键 [英] Key combination in VB.NET
本文介绍了VB.NET 中的组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我阅读 VB.NET 中的多个击键.例如,我想阅读 Control+P+H 组合键.我尝试了类似下面的代码但没有奏效...在表单按键
Can any one help me to read multiple key strokes in VB.NET.for Example, I want to read Control+P+H key combinations.I tried something like the code below but didn't work... In form Keydown
if e.control=true and e.keycode=keys.P and e.keycode=keys.H then
end if
推荐答案
好的,在阅读您的帖子后,根据我的理解,这样的事情应该可以解决问题.
Ok after reading your post and from what I can understand, something like this should do the trick.
Public Class Form1
Dim keyCombo As New List(Of Keys)({Keys.ControlKey, Keys.H, Keys.P})
Dim currentKeys As New List(Of Keys)
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
currentKeys.Add(e.KeyCode)
If currentKeys.Intersect(keyCombo).Count = keyCombo.Count Then
MessageBox.Show("CTRL + H + P Has Been Pressed....")
currentKeys.Clear()
End If
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
currentKeys.Remove(e.KeyCode)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
End Sub
End Class
如果您有任何问题,请告诉我,我会尽力回答它们,但是这应该能让您真正地走上正轨:)
If you have any questions, let me know and I will try my best to answer them, however this should get you well and truly on your way :)
这篇关于VB.NET 中的组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文