Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
private void CustomDateTimePicker_ValueChanged(object sender, EventArgs e)
    {


          SendKeys.Send("{RIGHT}");

     }


but when debug reach to SendKeys my system hangs
plz Please really I need help?
Posted
Updated 5-Jun-12 7:27am
v2
Comments
Sergey Alexandrovich Kryukov 5-Jun-12 15:04pm    
Is it Forms? Of something else? you need to tag it.
--SA

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?
 
Share this answer
 
Comments
nagiub2007 5-Jun-12 12:34pm    
Yes, I want to navigate or go to the next part when writing the day.
If I use Focus() method, I will achieve me goal. I want the CustomDateTimePicker works as the MaskedTextBox, when writing two digits in the Day's part the courser moved to the Month's part.

That I want to do !!
Sergey Alexandrovich Kryukov 5-Jun-12 15:09pm    
Please see my answer -- I explain how to do it correctly.
--SA
Sergey Alexandrovich Kryukov 5-Jun-12 15:04pm    
My 5, mostly for the idea of badly designed control. SendValues should not be used for the UI, and can rarely be used, if used at all.
--SA
codeBegin 6-Jun-12 7:10am    
my 5
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
 
Share this answer
 
Comments
codeBegin 6-Jun-12 7:10am    
my 5
Sergey Alexandrovich Kryukov 6-Jun-12 11:29am    
Thank you,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900