本文整理匯總了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;
}