Kaydol:
Kayıt Yorumları
(
Atom
)
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 C_Sharp_Form_HotKey
{
public partial class Form1 : Form
{
KeyboardHook hook;//control alt tuşlarını dinleme nesnesi
Form form2;//alt control f12 ile açmak istediğimiz form nesnesi
public Form1()
{
InitializeComponent();
//tuş dinleme nesnesinin örneğin oluşturma
hook = new KeyboardHook();
//bir tuşa basıldığında çalışan olan olay
hook.KeyPressed += new EventHandler (hook_KeyPressed);
//control alt F12 tuşlarına aynı anda basıldığında olay tetiklensin
//burayı HookModifierKeys enum değerlerine göre geniletebilirsiniz
hook.RegisterHotKey(HookModifierKeys.Control | HookModifierKeys.Alt, Keys.F12);
}
void hook_KeyPressed(object sender, KeyPressedEventArgs e)
{
//form2 açma fonksiyonunu çağır
form2Ac();
}
private void Form1_Load(object sender, EventArgs e)
{
//yapılacak olan işlemler
form2 = new Form2(this);
}
private void form2Ac()
{
//eğre form2 nesnesi daha önce oluşturulup kapatılmış ise yeni bir örneğini oluştur
if (form2.IsDisposed)
{
form2 = new Form2(this);
}
//form2 de form1 ile işlem yapmak
//için construtor (yapıcıya) this yani form nesnesini
//parametre olarak eklenebilir. Böylece ana formun bir referensını form2
//nesnesine taşımış oluruz.
//form2 nesnesini control alt F12 tuşlarına basılmış ise çalıştır
form2.Show();
}
}
}
Hiç yorum yok :
Yorum Gönder