search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

C# 偵測 複合鍵 – jashliao部落格

C# 偵測 複合鍵 (Ctrl + Alt + ○)


資料來源:https://dotblogs.com.tw/hung-chin/2011/10/02/38563


片段程式

                if (e.Control == true && e.Alt == true && e.KeyCode == Keys.T)//按住組合鍵 Ctrl + Alt + T
                {
                    MessageBox.Show("Ctrl + Alt + T");
                }

完整程式

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ex14
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)//按下ESC
            {
                Application.Exit();//關閉程式
            }
            else
            {
                if (e.Control == true && e.Alt == true && e.KeyCode == Keys.T)//按住組合鍵 Ctrl + Alt + T
                {
                    MessageBox.Show("Ctrl + Alt + T");
                }
            }
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //關閉程式前 確認視窗
            DialogResult Result = MessageBox.Show("尚未儲存確定要關閉程式?", "關閉確認", MessageBoxButtons.YesNo);
            if (Result == System.Windows.Forms.DialogResult.Yes)
            {
                // 關閉Form 
                e.Cancel = false;
            }
            else
            {
                e.Cancel = true;
            }
        }
    }
}



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦