Arnab Das Arnab Das -4 years ago 224
C# Question

Set focus on date field in DateTimePicker control in Windows form

I've a

control in my code. And I have used a custom format.

this.dateTimePickerDate.CustomFormat = "dd/MM/yyyy";
this.dateTimePickerDate.Value = System.DateTime.Now;

Now the requirement is to focus on the date part of the control. For example if this control shows 30/06/2011, after the form_load, then
from the date part should be selected or the cursor will be after the

Thanks in advance.

Answer Source

Maybe this code helps:

dateTimePicker1.GotFocus += new EventHandler(dateTimePicker1_GotFocus);

void dateTimePicker1_GotFocus(object sender, EventArgs e)
    SendKeys.Send("{RIGHT 1}");

And on form load set focus to datetimepicker.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download