本文整理汇总了C#中System.Windows.Forms.DateTimePicker.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimePicker.Focus方法的具体用法?C# DateTimePicker.Focus怎么用?C# DateTimePicker.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DateTimePicker
的用法示例。
在下文中一共展示了DateTimePicker.Focus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsDateRange
// Checks date format and range.
public static bool IsDateRange(DateTimePicker dStart, DateTimePicker dEnd)
{
DateTime start= Convert.ToDateTime(dStart.Text) ;
DateTime end = Convert.ToDateTime(dEnd.Text);
DateTime today = DateTime.Today;
if (start<today)
{
MessageBox.Show(" The start date can not be before today.", title);
dStart.Focus();
return false;
}
if (end < today)
{
MessageBox.Show(" The end date can not be before today.", title);
dStart.Focus();
return false;
}
if (start > end)
{
MessageBox.Show(" The start date can not be after the end date.", title);
dStart.Focus();
return false;
}
return true;
}
示例2: IsValidTimeRange
public static bool IsValidTimeRange(DateTimePicker dtpStartTime, DateTimePicker dtpEndTime, NumericUpDown numericUpDown)
{
// Check if the start time is after the end time.
if (dtpStartTime.Value > dtpEndTime.Value)
{
MessageBox.Show("The end time must be greater than the start time.", "Entry Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
dtpEndTime.Focus();
return false;
}
// TODO: Bug - The date time picker does not roll back to the previous day if the default
// end time is set for the next day. For example, if we start the program at 8:00 PM, the
// end time will be set for 12:00 AM the next day. This causes the validation to pass even
// if the form shows that the time range is too small.
// Check if at least two time slots can fit in the time range.
TimeSpan twoTimeSlotsSpan = TimeSpan.FromMinutes((int) numericUpDown.Value * 2);
if (dtpEndTime.Value - dtpStartTime.Value < twoTimeSlotsSpan)
{
MessageBox.Show("The difference between the start and end time must provide for at least two time slots.", "Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
dtpEndTime.Focus();
return false;
}
return true;
}
示例3: validateDate
private bool validateDate(DateTimePicker date)
{
if (date.Value > DateTime.Now)
{
Helper.showMessage("Date cannot be in future");
date.Focus();
return false;
}
return true;
}