Created
December 1, 2017 10:21
-
-
Save tamago324/34768ffff06e0cfb0c0b70cb01b93d1b to your computer and use it in GitHub Desktop.
親クラス(RootForm)側でキー押下イベントを制御し、RootFormを継承した子クラス(Form1)でキーとボタンで同じメソッドを扱う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Form1 | |
Public Overloads Sub F1Process() | |
MsgBox("F1!!!!") | |
End Sub | |
Public Overloads Sub F2Process() | |
MsgBox("F2!!!!") | |
End Sub | |
Private Sub ButtonF1_Click(sender As Object, e As EventArgs) Handles ButtonF1.Click | |
' F1ボタンクリック時にもF1押下時と同じ処理を呼び出す | |
F1Process() | |
End Sub | |
Private Sub ButtonF2_Click(sender As Object, e As EventArgs) Handles ButtonF2.Click | |
' F2ボタンクリック時にもF2押下時と同じ処理を呼び出す | |
F2Process() | |
End Sub | |
End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class RootForm | |
Private Sub RootForm_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp | |
' 子フォームのFnProcess()を呼ぶため | |
Dim form = CTypeDynamic(sender, sender.GetType()) | |
Select Case e.KeyCode | |
Case Keys.F1 | |
form.F1Process() | |
Case Keys.F2 | |
form.F2Process() | |
End Select | |
End Sub | |
''' <summary>F1キー押下時、F1ボタンクリック時の処理</summary> | |
Public Overridable Sub F1Process() | |
' オーバーライドしてください | |
End Sub | |
Public Overridable Sub F2Process() | |
' オーバーライドしてください | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment