前田稔(Maeda Minoru)の超初心者のプログラム入門
ファイル名 | 説明 |
---|---|
EscKey.cs | ESC キーで終了 |
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) { if ((int)(byte)e.KeyChar == (int)System.Windows.Forms.Keys.Escape) // プログラムを終了 this.Dispose(); //Application.Exit(); } |
/*************************************************/ /*★ ESC キーでプログラムを終了する 前田 稔 ★*/ /*************************************************/ using System; using System.Drawing; using System.Windows.Forms; public class MyForm : Form { public MyForm() { } protected override void OnKeyDown(KeyEventArgs e) { switch(e.KeyCode) { case Keys.Escape: // プログラムを終了 this.Dispose(); //Application.Exit(); break; } } } class key { public static void Main() { MyForm mf = new MyForm(); Application.Run(mf); } } |
public MyForm() { KeyDown += new KeyEventHandler(OnMyKeyDown); } |
protected void OnMyKeyDown(object sender, KeyEventArgs e) { ・・・ } |
#define VK_CLEAR 0x0C #define VK_RETURN 0x0D #define VK_SHIFT 0x10 #define VK_CONTROL 0x11 #define VK_MENU 0x12 #define VK_PAUSE 0x13 #define VK_CAPITAL 0x14 #define VK_KANA 0x15 #define VK_HANGEUL 0x15 /* old name - should be here for compatibility */ #define VK_HANGUL 0x15 #define VK_JUNJA 0x17 #define VK_FINAL 0x18 #define VK_HANJA 0x19 #define VK_KANJI 0x19 #define VK_ESCAPE 0x1B #define VK_CONVERT 0x1C #define VK_NONCONVERT 0x1D #define VK_ACCEPT 0x1E #define VK_MODECHANGE 0x1F #define VK_SPACE 0x20 #define VK_PRIOR 0x21 #define VK_NEXT 0x22 #define VK_END 0x23 #define VK_HOME 0x24 #define VK_LEFT 0x25 #define VK_UP 0x26 #define VK_RIGHT 0x27 #define VK_DOWN 0x28 #define VK_SELECT 0x29 #define VK_PRINT 0x2A #define VK_EXECUTE 0x2B #define VK_SNAPSHOT 0x2C #define VK_INSERT 0x2D #define VK_DELETE 0x2E #define VK_HELP 0x2F #define VK_F1 0x70 #define VK_F2 0x71 #define VK_F3 0x72 #define VK_F4 0x73 #define VK_F5 0x74 |