我想知道这里是否有任何方法可以将自定义常量添加到系统常量中。
例如在我的编码中,我经常使用这样的代码:
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);
}
}
想法是向枚举键添加新元素,说“查找”所以我可以这样做:
VB.NET
If e.KeyCode = Keys.Find Then
search(mytextbox.Text.Trim)
End If
C#
if (e.KeyCode == Keys.Find) {
search(mytextbox.Text.Trim);
}
当然,我会首先在 Applicaton 级别的某个较低级别的“ProcessCmdKey”中将按键 Keys.F3 和 e.Control+Keys.F 替换为 Keys.Find,如下所示:
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
所以,问题是:可以将 Keys.Find 添加到 Keys 常量中吗?如果这样做 - 如何?