コード例 #1
0
 private void FrmMain_Load(object sender, System.EventArgs e)
 {
     if (File.Exists(Application.StartupPath + "\\HotkeyValue.txt"))
     {
         StreamReader reader = File.OpenText(Application.StartupPath + "\\HotkeyValue.txt");
         int          val    = -1;
         try
         {
             val = Int32.Parse(reader.ReadToEnd().Trim());
         }
         catch {}
         if (val != -1)
         {
             Keys k       = (Keys)val;
             bool success = FrmMain.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), ShortcutInput.Win32ModifiersFromKeys(k), ShortcutInput.CharCodeFromKeys(k));
             if (success)
             {
                 TxtKeyEnumValue.Text = val.ToString();
             }
             else
             {
                 MessageBox.Show("Could not register Hotkey - there is probably a conflict.  ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
コード例 #2
0
 public FrmMain()
 {
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     if (File.Exists(Application.StartupPath + "\\HotkeyValue.txt"))
     {
         StreamReader reader = File.OpenText(Application.StartupPath + "\\HotkeyValue.txt");
         int          val    = -1;
         try
         {
             val = Int32.Parse(reader.ReadToEnd().Trim());
         }
         catch { }
         if (val != -1)
         {
             Keys k       = (Keys)val;
             bool success = FrmMain.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), ShortcutInput.Win32ModifiersFromKeys(k), ShortcutInput.CharCodeFromKeys(k));
             if (success)
             {
                 TxtKeyEnumValue.Text = val.ToString();
             }
             else
             {
                 MessageBox.Show("Could not register Hotkey - there is probably a conflict.  ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
コード例 #3
0
        private void BtnChangeHotkey_Click(object sender, System.EventArgs e)
        {
            byte minMod            = (byte)NumMinMod.Value;
            Keys k                 = (TxtKeyEnumValue.Text.Length > 0) ? (Keys)Int32.Parse(TxtKeyEnumValue.Text) : Keys.None;
            FrmSpecifyShortcut frm = new FrmSpecifyShortcut(minMod, k);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                bool success = FrmMain.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), frm.ShortcutInput1.Win32Modifiers, frm.ShortcutInput1.CharCode);
                if (success)
                {
                    TxtKeyEnumValue.Text = ((int)frm.ShortcutInput1.Keys).ToString();
                    StreamWriter writer = File.CreateText(Application.StartupPath + "\\HotkeyValue.txt");
                    writer.Write(TxtKeyEnumValue.Text);
                    writer.Close();
                }
                else
                {
                    MessageBox.Show("Could not register Hotkey - there is probably a conflict.  ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }