habibb
یک شنبه 01 دی 1392, 22:57 عصر
سلام.
اگر دکمه ای بر روی فرم قرار دهیم و بخواهیم تفاوت اجرای این 4 رویداد ( PreviewKeyDown و KeyPress و KeyDown و KeyUp) را در هنگام زدن دکمه های صفحه کلید با هم مقایسه کنیم .
به این نتایج می رسیم↓
فقط دکمه های زیر رویداد KeyPress را اجرا می کنند
ولی بقیه ی رویداد ها را اجرا نمی کنند!؟!:متعجب:چرا؟:متعجب:
دکمه ها عبارتند از : 1 2 3 4 5 6 7 8 9 0 (اعداد بالای حروف نه قسمت ماشین حسابی) و فاصلهSpace
و q w e r t y u i o p [ ] ` a s d f g h j k l ; ' z x c v b n m , . / \
حالا دکمه هایی که چند رویداد رو با هم به ترتیب زیر اجرا می کنند بازم چرا؟:متعجب:
به ترتیب عبارتند از : PreviewKeyDown و KeyPress و KeyDown
این دکمه ها دکمه های قسمت ماشین حسابی صفحه کلید می باشند بجز Enter همچنین BackSpace هم هست!
حالا دکمه هایی هستند که به ترتیب PreviewKeyDown و KeyDown را اجرا می کنند؟ بازم چرا؟:متعجب:
عبارتند از : Shift Control Alt Capslock Delete End PageUp PageDown Home End و دکمه های سوئیچ F ها
دکمه هایی هم هستند که فقط رویداد PreviewKeyDown را اجرا می کنند
که عبارتند از : هر دو Enter موجود در صفحه کلید و دکمه های ArrowKeys و Escape
حالا سوال تناقض در تعریف این رویداد ها ست؟ نظرتان چیست ؟ آیا این رویداد ها در تمام ویندوز ها این گونه هستند؟:متفکر:
طبق تعریف ؟ اگر کلیدی فشرده شود باید این 4 رویداد همه اتفاق افتند؟:متفکر:
در ضمن منابعی ذکر کنید در این مورد
متشکرم
private void button1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
MessageBox.Show("button1_PreviewKeyDown");
}
private void button1_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show("button1_KeyPress");
}
private void button1_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("button1_KeyDown");
}
private void button1_KeyUp(object sender, KeyEventArgs e)
{
MessageBox.Show("button1_KeyUp");
}
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=vs.110).as px
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.previewkeydown(v=vs.1 10).aspx
اگر دکمه ای بر روی فرم قرار دهیم و بخواهیم تفاوت اجرای این 4 رویداد ( PreviewKeyDown و KeyPress و KeyDown و KeyUp) را در هنگام زدن دکمه های صفحه کلید با هم مقایسه کنیم .
به این نتایج می رسیم↓
فقط دکمه های زیر رویداد KeyPress را اجرا می کنند
ولی بقیه ی رویداد ها را اجرا نمی کنند!؟!:متعجب:چرا؟:متعجب:
دکمه ها عبارتند از : 1 2 3 4 5 6 7 8 9 0 (اعداد بالای حروف نه قسمت ماشین حسابی) و فاصلهSpace
و q w e r t y u i o p [ ] ` a s d f g h j k l ; ' z x c v b n m , . / \
حالا دکمه هایی که چند رویداد رو با هم به ترتیب زیر اجرا می کنند بازم چرا؟:متعجب:
به ترتیب عبارتند از : PreviewKeyDown و KeyPress و KeyDown
این دکمه ها دکمه های قسمت ماشین حسابی صفحه کلید می باشند بجز Enter همچنین BackSpace هم هست!
حالا دکمه هایی هستند که به ترتیب PreviewKeyDown و KeyDown را اجرا می کنند؟ بازم چرا؟:متعجب:
عبارتند از : Shift Control Alt Capslock Delete End PageUp PageDown Home End و دکمه های سوئیچ F ها
دکمه هایی هم هستند که فقط رویداد PreviewKeyDown را اجرا می کنند
که عبارتند از : هر دو Enter موجود در صفحه کلید و دکمه های ArrowKeys و Escape
حالا سوال تناقض در تعریف این رویداد ها ست؟ نظرتان چیست ؟ آیا این رویداد ها در تمام ویندوز ها این گونه هستند؟:متفکر:
طبق تعریف ؟ اگر کلیدی فشرده شود باید این 4 رویداد همه اتفاق افتند؟:متفکر:
در ضمن منابعی ذکر کنید در این مورد
متشکرم
private void button1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
MessageBox.Show("button1_PreviewKeyDown");
}
private void button1_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show("button1_KeyPress");
}
private void button1_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("button1_KeyDown");
}
private void button1_KeyUp(object sender, KeyEventArgs e)
{
MessageBox.Show("button1_KeyUp");
}
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=vs.110).as px
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.previewkeydown(v=vs.1 10).aspx