FunctionkeyをButtonに割り当てたいのですが、どのようにすれば
よいのでしょうか?ご教授ください。
こういうこと?
Option Explicit
Private Sub PushFKey(pKeyCode As Integer)
Select Case pKeyCode
Case vbKeyF1
MsgBox "F1 Pushed!!"
Case vbKeyF2
MsgBox "F2 Pushed!!"
Case Else
MsgBox "Any Key Pushed!!"
End Select
End Sub
Private Sub Command1_Click(Index As Integer)
Call PushFKey(Index + vbKeyF1)
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF1, vbKeyF2, vbKeyF3, vbKeyF4, _
vbKeyF5, vbKeyF6, vbKeyF7, vbKeyF8, _
vbKeyF9, vbKeyF10, vbKeyF11, vbKeyF12
Call PushFKey(KeyCode)
End Select
End Sub
Private Sub Form_Load()
Dim i As Long
Me.KeyPreview = True
With Command1(0)
.Left = 120
.Top = 120
.Height = 495
.Width = 615
.Caption = "F1"
End With
For i = 1 To 11
Load Command1(i)
With Command1(i)
.Left = Command1(i - 1).Left + Command1(i - 1).Width
.Caption = "F" & CStr(i + 1)
.Visible = True
End With
Next
End Sub
ツイート | ![]() |