SendKeys.Send使我的系统挂起 [英] SendKeys.Send make my system hangs

查看:94
本文介绍了SendKeys.Send使我的系统挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了adatetimepicker自定义控件
我的日期格式是yyyy/MM/dd
我想输入年份yyyy的4位数字,然后课程进入月份部分,依此类推
因此,在CustomDateTimePicker_ValueChanged事件中,我编写了此代码

i developed adatetimepicker custom control
my date format is yyyy/MM/dd
i want to typed 4 digit of year yyyy then courser go to month section and so on
so in CustomDateTimePicker_ValueChanged event i wrote this code

private void CustomDateTimePicker_ValueChanged(object sender, EventArgs e)
    {


          SendKeys.Send("{RIGHT}");

     }



但是当调试到达SendKeys时,我的系统挂起
plz 请问我真的需要帮助吗?



but when debug reach to SendKeys my system hangs
plz Please really I need help?

推荐答案

机会是因为您是从ValueChanged事件处理程序发送此消息的,所以SendKeys将向当前控件发送一个右键-即CustomDateTimePicker,并且它(无论出于何种原因)都会导致ValueChanged事件.发出一个RIGHT,这导致...您明白了.

为什么要发送密钥?通常,这是控件设计错误的一个示例-您试图实现什么,以为您认为这是一个很好的解决方案?为什么不只使用Focus方法将焦点设置为月份呢?
The chances are that because you are sending this from a ValueChanged event handler, the effect of the SendKeys is to send a RIGHT key to the current control - i.e. the CustomDateTimePicker, and that it is (for whatever reason) causing a ValueChanged Event. Which sends a RIGHT, which causes... you get the idea.

Why are you sending keys around? Normally, that is an example of a badly designed control - what are you trying to achieve that you think this is a good solution? Why not just use the Focus method to set the focus to the month?


请查看我对OriginalGriff答案的评论.切勿将SendKeys用于此类情况.您可以将System.Windows.Forms.Control.SelectNextControlSystem.Windows.Forms.Control.GetNextControlSystem.Windows.Forms.Control.Focus结合使用.请参阅:
http://msdn.microsoft.com/en-us/library/system. windows.forms.control.aspx [ ^ ].

—SA
Please see my comment to the answer by OriginalGriff. Never use SendKeys for such things. You can use System.Windows.Forms.Control.SelectNextControl, or System.Windows.Forms.Control.GetNextControl in combination with System.Windows.Forms.Control.Focus. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[^].

—SA


这篇关于SendKeys.Send使我的系统挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆