Control.KeyUp 事件
在控件有焦点的情况下释放键时发生。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Public Event KeyUp As KeyEventHandler
用法
Dim instance As Control
Dim handler As KeyEventHandler
AddHandler instance.KeyUp, handler
public event KeyEventHandler KeyUp
public:
event KeyEventHandler^ KeyUp {
void add (KeyEventHandler^ value);
void remove (KeyEventHandler^ value);
}
/** @event */
public void add_KeyUp (KeyEventHandler value)
/** @event */
public void remove_KeyUp (KeyEventHandler value)
JScript 支持使用事件,但不支持进行新的声明。
备注
键事件按下列顺序发生:
若要仅在窗体级别处理键盘事件而不允许其他控件接收键盘事件,请将窗体的 KeyPress 事件处理方法中的 KeyPressEventArgs.Handled 属性设置为 true。某些键,如 Tab、Return、Esc 和箭头键,由控件自动处理。为使这些键引发 KeyUp 事件,必须在窗体上的每个控件中重写 IsInputKey 方法。用于重写 IsInputKey 的代码需要确定是否按下了某个特殊键,并且需要返回一个 true 值。
有关处理事件的更多信息,请参见 使用事件。
示例
下面的代码示例使用带有 Help 类的 KeyUp 事件向用户显示弹出样式帮助。
' This example demonstrates how to use the KeyUp event with the Help class to display
' pop-up style help to the user of the application. When the user presses F1, the Help
' class displays a pop-up window, similar to a ToolTip, near the control. This example assumes
' that a TextBox control, named textBox1, has been added to the form and its KeyUp
' event has been contected to this event handler method.
Private Sub textBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textBox1.KeyUp
' Determine whether the key entered is the F1 key. Display help if it is.
If e.KeyCode = Keys.F1 Then
' Display a pop-up help topic to assist the user.
Help.ShowPopup(textBox1, "Enter your first name", New Point(textBox1.Right, Me.textBox1.Bottom))
End If
End Sub 'textBox1_KeyUp
// This example demonstrates how to use the KeyUp event with the Help class to display
// pop-up style help to the user of the application. When the user presses F1, the Help
// class displays a pop-up window, similar to a ToolTip, near the control. This example assumes
// that a TextBox control, named textBox1, has been added to the form and its KeyUp
// event has been contected to this event handler method.
private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
// Determine whether the key entered is the F1 key. Display help if it is.
if(e.KeyCode == Keys.F1)
{
// Display a pop-up help topic to assist the user.
Help.ShowPopup(textBox1, "Enter your first name", new Point(textBox1.Right, this.textBox1.Bottom));
}
}
// This example demonstrates how to use the KeyUp event with the Help class to display
// pop-up style help to the user of the application. When the user presses F1, the Help
// class displays a pop-up window, similar to a ToolTip, near the control. This example assumes
// that a TextBox control, named textBox1, has been added to the form and its KeyUp
// event has been connected to this event handler method.
private:
void textBox1_KeyUp( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
{
// Determine whether the key entered is the F1 key. Display help if it is.
if ( e->KeyCode == Keys::F1 )
{
// Display a pop-up help topic to assist the user.
Help::ShowPopup( textBox1, "Enter your first name", Point(textBox1->Right,this->textBox1->Bottom) );
}
}
// This example demonstrates how to use the KeyUp event with the Help
// class to display pop-up style help to the user of the application.
// When the user presses F1, the Help class displays a pop-up window,
// similar to a ToolTip, near the control. This example assumes that a
// TextBox control, named textBox1, has been added to the form and its
// KeyUp event has been contected to this event handler method.
private void textBox1_KeyUp(Object sender,
System.Windows.Forms.KeyEventArgs e)
{
// Determine whether the key entered is the F1 key.
// Display help if it is.
if (e.get_KeyCode().Equals(Keys.F1)) {
// Display a pop-up help topic to assist the user.
Help.ShowPopup(textBox1, "Enter your first name",
new Point(textBox1.get_Right(), this.textBox1.get_Bottom()));
}
} //textBox1_KeyUp
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
Control 类
Control 成员
System.Windows.Forms 命名空间
OnKeyUp
Control.KeyDown 事件
Control.KeyPress 事件