更新:2007 年 11 月
通常,Smartphone 软键操作菜单;然而,通过从窗体中移除 MainMenu 组件,可以提供自定义软键功能。当 Smartphone 应用程序中不存在菜单时,按下软键 1 和按下软键 2 都会引发 KeyDown 事件,当释放键时会接着引发 KeyUp 事件。
KeyCode 字段将 F1 识别为软键 1,而将 F2 识别为软键 2。
示例
下面的代码示例演示如何为按下软键提供事件处理代码。
Visual C# 用户需要在窗体的构造函数中为 KeyPress 事件定义一个事件处理程序。
// Connect an event handler to the KeyPress event
this.KeyPress += new KeyPressEventHandler(OnKeyPress);
Private Sub keypressed(ByVal o As [Object], _
ByVal e As KeyPressEventArgs) Handles MyBase.KeyPress
' Determine if ESC key value is raised.
If e.KeyChar = ChrW(27) Then
' Handle the event to provide your own functionality.
e.Handled = True
' Add your event handling code here.
MessageBox.Show("Custom back key functionality.")
End If
End Sub
private void OnKeyPress(object sender, KeyPressEventArgs ke)
{
// Determine if ESC key value is raised.
if (ke.KeyChar == (Char)Keys.Escape)
{
// Handle the event to provide functionality.
ke.Handled = true;
// Add your event handling code here.
MessageBox.Show("Custom back key functionality.");
}
}
编译代码
此示例需要引用下面的命名空间: