Ben C# 'da yeniyim. Ben sadece sayıları ve bir ondalık kabul eden bir metin kutusu olan bir windows 10 uygulaması yapmaya çalışıyorum. Burada KeyPress olay işleyicisini kullanmak için birçok insan gördüm, ama bende yok. Sadece KeyDown ve KeyUp var.KeyPress olay işleyicisini bulamıyorum C#
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key < Key.D0 || e.Key > Key.D9)
{
e.Handled = true;
}
}
ama hata alıyorum hatta bunun için Key.D0 ve Key.D9 için "Anahtar geçerli bağlamda yok": Ben KeyDown ile aşağıdaki kodu kullanarak birisi görmüşse. Birileri bunun harika olacağını düşünürse tam bir kayıptayım. Bu yardımcı olabilir
// This event occurs after the KeyDown event and can be used to prevent
// characters from entering the control.
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
// Check for the condition
if (SOME CONDITION)
{
// Stop the character from being entered into the control.
e.Handled = true;
}
}
Hope:
WinForm veya WPF? –
'Keys.D0' ve' Keys.D9' – NineBerry
olmalıdır. Windows 10 uygulaması derken, bir "Evrensel Uygulama" yazmak istediğiniz anlamına mı geliyor? – NineBerry