public Form1()
{
InitializeComponent();
this.radDateTimePicker1.MaskProviderCreated += RadDateTimePicker1_MaskProviderCreated;
this.radDateTimePicker1.DateTimePickerElement.ShowCurrentTime = false;
this.radDateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.radDateTimePicker1.Culture = new System.Globalization.CultureInfo("en-US");
this.radDateTimePicker1.CustomFormat = "hh:mm:ss tt";
this.radDateTimePicker1.Value = new System.DateTime(2025, 6, 12, 12, 4, 34, 562);
}
Hello Jackson,
Thank you for reporting this. Here is a possible workaround. In a few words, we need to override the HandleAmPmKeyPress method in the MaskDateTimeProvider of the control and handle this scenario.
public Form1()
{
InitializeComponent();
this.radDateTimePicker1.MaskProviderCreated += RadDateTimePicker1_MaskProviderCreated;
this.radDateTimePicker1.DateTimePickerElement.ShowCurrentTime = false;
this.radDateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.radDateTimePicker1.Culture = new System.Globalization.CultureInfo("en-US");
this.radDateTimePicker1.CustomFormat = "hh:mm:ss tt";
}
private void RadDateTimePicker1_MaskProviderCreated(object sender, EventArgs e)
{
this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.Provider = new CustomProvider(this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.Mask, this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.Culture, this.radDateTimePicker1.DateTimePickerElement.TextBoxElement);
}
public class CustomProvider : MaskDateTimeProvider
{
public CustomProvider(string mask, CultureInfo culture, RadMaskedEditBoxElement owner) : base(mask, culture, owner)
{
}
protected override void HandleAmPmKeyPress(KeyPressEventArgs e)
{
// base.HandleAmPmKeyPress(e);
char am = this.Culture.DateTimeFormat.AMDesignator.ToLower()[0];
char pm = this.Culture.DateTimeFormat.PMDesignator.ToLower()[0];
var field = this.GetType().BaseType.GetField("value", BindingFlags.Instance |
BindingFlags.NonPublic |
BindingFlags.DeclaredOnly);
DateTime valueObjectCache = (DateTime)field.GetValue(this);
if (am == char.ToLower(e.KeyChar))
{
if (valueObjectCache.Hour >= 12)
{
this.Value = valueObjectCache.AddHours(-12);
}
}
else if (pm == char.ToLower(e.KeyChar))
{
if (valueObjectCache.Hour < 12)
{
this.Value = valueObjectCache.AddHours(12);
}
}
}
}
Regards,
Dinko | Tech Support Engineer
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.