SORU
18 ŞUBAT 2010, PERŞEMBE


Düğme Windows Forms C formu kapatmak için Escape#

Aşağıdaki denedim:

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if ((Keys) e.KeyValue == Keys.Escape)
        this.Close();
}

Ama çalışmıyor.

Sonra bunu denedim:

protected override void OnKeyDown(KeyEventArgs e)
{
    base.OnKeyDown(e);
    if (e.KeyCode == Keys.Escape)
        this.Close();
}

Ve hala hiçbir şey işe yaramıyor.

True form özelliklerini ayarlamak benim windows KeyPreview... Neyi yanlış yapıyorum?

CEVAP
18 ŞUBAT 2010, PERŞEMBE


Bu her zaman, uygun olay işleyicisi atama, KeyPreview ne olursa olsun, CancelButton vb çalışır:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
        if (keyData == Keys.Escape) {
            this.Close();
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • oHeymarvin

    oHeymarvin

    11 Temmuz 2013
  • Snazzy Labs

    Snazzy Labs

    9 Aralık 2008
  • theatre2film

    theatre2film

    12 NİSAN 2006