Delphi easy way to exit a program by pressing ESC shortcut key

Source: Internet
Author: User

The first method:

Put a button on the form:

1>, set the Cancel property of the button to true;

2>, write in the Click event of the button:

Procedure Tform1.btn1click (Sender:tobject);
Begin
Close;
End

button's Cancel property:
This property determines whether the button is a Cancel button. When set to True, the Cancel button, which executes the button's OnClick event handler, is executed when the user presses the ESC key. When there are multiple cancel buttons in the form, only the OnClick event of the tab Order Property minimum button is called.

The second method:

1> Set the KeyPreview property of the form to: true;//can receive keyboard actions

2>, write in the keyboard event of the form:

Procedure tform1.formkeypress (Sender:tobject; var key:char);
Begin
If key = #27 Then
Application.terminate; Close Program
End

Delphi easy way to exit a program by pressing ESC shortcut key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.