PrintPreviewDialog.KeyPreview PrintPreviewDialog.KeyPreview PrintPreviewDialog.KeyPreview PrintPreviewDialog.KeyPreview Property

定义

获取或设置一个值,该值指示在将键事件传递到具有焦点的控件前,窗体是否将接收此键事件。Gets or sets a value indicating whether the form will receive key events before the event is passed to the control that has focus.

public:
 property bool KeyPreview { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool KeyPreview { get; set; }
member this.KeyPreview : bool with get, set
Public Property KeyPreview As Boolean

属性值

如果窗体将接收所有键事件,则为 true;如果窗体上当前选定控件接收键事件,则为 falsetrue if the form will receive all key events; false if the currently selected control on the form receives key events. 默认值为 falseThe default is false.

注解

此属性与此类无关。This property is not relevant for this class.

当此属性设置true为时, 窗体将接收所有KeyPressKeyDownKeyUp事件。When this property is set to true, the form will receive all KeyPress, KeyDown, and KeyUp events. 在窗体的事件处理程序处理完击键后, 会将击键分配给具有焦点的控件。After the form's event handlers have completed processing the keystroke, the keystroke is then assigned to the control with focus.

您可以使用此属性来处理应用程序中的所有击键, 并处理击键或调用相应的控件来处理击键。You can use this property to process all keystrokes in your application and either handle the keystroke or call the appropriate control to handle the keystroke. 例如, 当应用程序使用函数键时, 您可能希望在窗体级别处理击键, 而不是为可能接收击键事件的每个控件都编写代码。For example, when an application uses function keys, you might want to process the keystrokes at the form level rather than writing code for each control that might receive keystroke events.

备注

如果窗体没有可见或启用的控件, 则它会自动接收所有键盘事件。If a form has no visible or enabled controls, it automatically receives all keyboard events.

适用于