I'm wonder if here is any way to add custom constant to system constants.
For example in my coding I often uses such code:
VB.NET
Private Sub myform_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F3 Or (e.Control And e.KeyCode = Keys.F) Then
search(mytextbox.Text.Trim)
End If
End Sub
C#
private void myform_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.F3 | (e.Control & e.KeyCode == Keys.F)) {
search(mytextbox.Text.Trim);
}
}
Idea is to add new element to Enum Keys, say "Find" So I would be able to do this:
VB.NET
If e.KeyCode = Keys.Find Then
search(mytextbox.Text.Trim)
End If
C#
if (e.KeyCode == Keys.Find) {
search(mytextbox.Text.Trim);
}
Of course I would first replace keystrokes Keys.F3 and e.Control+Keys.F to Keys.Find in some lower level "ProcessCmdKey" on Applicaton level like this:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = Keys.F3 Then
msg.WParam = CType(Keys.Find, IntPtr)
keyData = Keys.Find
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
So, question is: Could Keys.Find be added to Keys constants and if do - how?