Delphi สอนวิธีทำให้กดปุ่ม ESC แล้วปิดฟอร์ม

สวัสดีครับ กลับมาบันทึกเรื่องราวเทคนิค Delphi กันอีกหน่อย พอไม่ค่อยได้ใช้ก็หลงๆลืมๆไปนั่นก็คือการใช้ Hot key นั่นเอง

หลายครั้งเราก็เบื่อที่จะต้องลากเมาส์ไปยังด้านบนสุดของฟอร์มเพื่อจะกดปิดทุกครั้ง อยากจะกด ESC แล้วฟอร์มที่เปิดอยู่ปิดได้เลยเหมือนกับ Dialog ผมมีวิธีมาบอกครับ

ขั้นแรกใน Properties ของ Form เราเลือกให้ KeyPreview เป็น True

จากนั้นเขียน Code อีกนิดหน่อย ใน Event ที่ชื่อว่า OnKeyPress ของ Form

if key=chr(27) then
close;

ซึ่ง 27 คือ ASCII ของ ปุ่ม ESC นั่นเอง

เท่านี้เวลาจะปิด Form เรากด ESC หน้านี้จะปิดให้เองครับ

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response

More from Piyanat Nimkhuntod