0001.
public
class
DateTimePicker : Control {
0002.
0003.
protected
static
readonly
Color DefaultTitleBackColor = SystemColors.ActiveCaption;
0004.
0005.
protected
static
readonly
Color DefaultTitleForeColor = SystemColors.ActiveCaptionText;
0006.
0007.
protected
static
readonly
Color DefaultMonthBackColor = SystemColors.Window;
0008.
0009.
protected
static
readonly
Color DefaultTrailingForeColor = SystemColors.GrayText;
0010.
0011.
private
static
readonly
object
EVENT_FORMATCHANGED =
new
object
();
0012.
0013.
private
const
int
TIMEFORMAT_NOUPDOWN = NativeMethods.DTS_TIMEFORMAT & (~NativeMethods.DTS_UPDOWN);
0014.
private
EventHandler onCloseUp;
0015.
private
EventHandler onDropDown;
0016.
private
EventHandler onValueChanged;
0017.
private
EventHandler onRightToLeftLayoutChanged;
0018.
0019.
0020.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0021.
public
static
readonly
DateTime MinDateTime =
new
DateTime(1753, 1, 1);
0022.
0023.
0024.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0025.
public
static
readonly
DateTime MaxDateTime =
new
DateTime(9998, 12, 31);
0026.
0027.
private
int
style;
0028.
private
short
prefHeightCache = -1;
0029.
0030.
0031.
private
bool
validTime =
true
;
0032.
0033.
0034.
private
bool
userHasSetValue =
false
;
0035.
private
DateTime value = DateTime.Now;
0036.
private
DateTime creationTime = DateTime.Now;
0037.
0038.
private
DateTime max = DateTime.MaxValue;
0039.
private
DateTime min = DateTime.MinValue;
0040.
private
Color calendarForeColor = DefaultForeColor;
0041.
private
Color calendarTitleBackColor = DefaultTitleBackColor;
0042.
private
Color calendarTitleForeColor = DefaultTitleForeColor;
0043.
private
Color calendarMonthBackground = DefaultMonthBackColor;
0044.
private
Color calendarTrailingText = DefaultTrailingForeColor;
0045.
private
Font calendarFont =
null
;
0046.
private
FontHandleWrapper calendarFontHandleWrapper =
null
;
0047.
0048.
0049.
private
string
customFormat;
0050.
0051.
private
DateTimePickerFormat format;
0052.
0053.
private
bool
rightToLeftLayout =
false
;
0054.
0055.
0056.
public
DateTimePicker()
0057.
:
base
() {
0058.
0059.
SetState2(STATE2_USEPREFERREDSIZECACHE,
true
);
0060.
0061.
SetStyle(ControlStyles.FixedHeight,
true
);
0062.
0063.
0064.
SetStyle(ControlStyles.UserPaint |
0065.
ControlStyles.StandardClick,
false
);
0066.
0067.
0068.
format = DateTimePickerFormat.Long;
0069.
}
0070.
0071.
0072.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0073.
public
override
Color BackColor {
0074.
get
{
0075.
if
(ShouldSerializeBackColor()) {
0076.
return
base
.BackColor;
0077.
}
0078.
else
{
0079.
return
SystemColors.Window;
0080.
}
0081.
}
0082.
set
{
0083.
base
.BackColor = value;
0084.
}
0085.
}
0086.
0087.
0088.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0089.
new
public
event
EventHandler BackColorChanged {
0090.
add {
0091.
base
.BackColorChanged += value;
0092.
}
0093.
remove {
0094.
base
.BackColorChanged -= value;
0095.
}
0096.
}
0097.
0098.
0099.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0100.
public
override
Image BackgroundImage {
0101.
get
{
0102.
return
base
.BackgroundImage;
0103.
}
0104.
set
{
0105.
base
.BackgroundImage = value;
0106.
}
0107.
}
0108.
0109.
0110.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0111.
new
public
event
EventHandler BackgroundImageChanged {
0112.
add {
0113.
base
.BackgroundImageChanged += value;
0114.
}
0115.
remove {
0116.
base
.BackgroundImageChanged -= value;
0117.
}
0118.
}
0119.
0120.
0121.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0122.
public
override
ImageLayout BackgroundImageLayout {
0123.
get
{
0124.
return
base
.BackgroundImageLayout;
0125.
}
0126.
set
{
0127.
base
.BackgroundImageLayout = value;
0128.
}
0129.
}
0130.
0131.
0132.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0133.
new
public
event
EventHandler BackgroundImageLayoutChanged {
0134.
add {
0135.
base
.BackgroundImageLayoutChanged += value;
0136.
}
0137.
remove {
0138.
base
.BackgroundImageLayoutChanged -= value;
0139.
}
0140.
}
0141.
0142.
0143.
[
0144.
SRCategory(SR.CatAppearance),
0145.
SRDescription(SR.DateTimePickerCalendarForeColorDescr)
0146.
]
0147.
public
Color CalendarForeColor {
0148.
get
{
0149.
return
calendarForeColor;
0150.
}
0151.
0152.
set
{
0153.
if
(value.IsEmpty) {
0154.
throw
new
ArgumentException(SR.GetString(SR.InvalidNullArgument,
0155.
"value"
));
0156.
}
0157.
if
(!value.Equals(calendarForeColor)) {
0158.
calendarForeColor = value;
0159.
SetControlColor(NativeMethods.MCSC_TEXT, value);
0160.
}
0161.
}
0162.
}
0163.
0164.
0165.
[
0166.
SRCategory(SR.CatAppearance),
0167.
Localizable(
true
),
0168.
AmbientValue(
null
),
0169.
SRDescription(SR.DateTimePickerCalendarFontDescr)
0170.
]
0171.
public
Font CalendarFont {
0172.
get
{
0173.
if
(calendarFont ==
null
) {
0174.
return
Font;
0175.
}
0176.
return
calendarFont;
0177.
}
0178.
0179.
set
{
0180.
if
((value ==
null
&& calendarFont !=
null
) || (value !=
null
&& !value.Equals(calendarFont))) {
0181.
calendarFont = value;
0182.
calendarFontHandleWrapper =
null
;
0183.
SetControlCalendarFont();
0184.
}
0185.
}
0186.
}
0187.
0188.
private
IntPtr CalendarFontHandle {
0189.
get
{
0190.
if
(calendarFont ==
null
) {
0191.
Debug.Assert(calendarFontHandleWrapper ==
null
,
"font handle out of [....] with Font"
);
0192.
return
FontHandle;
0193.
}
0194.
0195.
if
(calendarFontHandleWrapper ==
null
) {
0196.
calendarFontHandleWrapper =
new
FontHandleWrapper(CalendarFont);
0197.
}
0198.
0199.
return
calendarFontHandleWrapper.Handle;
0200.
}
0201.
}
0202.
0203.
0204.
[
0205.
SRCategory(SR.CatAppearance),
0206.
SRDescription(SR.DateTimePickerCalendarTitleBackColorDescr)
0207.
]
0208.
public
Color CalendarTitleBackColor {
0209.
get
{
0210.
return
calendarTitleBackColor;
0211.
}
0212.
0213.
set
{
0214.
if
(value.IsEmpty) {
0215.
throw
new
ArgumentException(SR.GetString(SR.InvalidNullArgument,
0216.
"value"
));
0217.
}
0218.
if
(!value.Equals(calendarTitleBackColor)) {
0219.
calendarTitleBackColor = value;
0220.
SetControlColor(NativeMethods.MCSC_TITLEBK, value);
0221.
}
0222.
}
0223.
}
0224.
0225.
0226.
[
0227.
SRCategory(SR.CatAppearance),
0228.
SRDescription(SR.DateTimePickerCalendarTitleForeColorDescr)
0229.
]
0230.
public
Color CalendarTitleForeColor {
0231.
get
{
0232.
return
calendarTitleForeColor;
0233.
}
0234.
0235.
set
{
0236.
if
(value.IsEmpty) {
0237.
throw
new
ArgumentException(SR.GetString(SR.InvalidNullArgument,
0238.
"value"
));
0239.
}
0240.
if
(!value.Equals(calendarTitleForeColor)) {
0241.
calendarTitleForeColor = value;
0242.
SetControlColor(NativeMethods.MCSC_TITLETEXT, value);
0243.
}
0244.
}
0245.
}
0246.
0247.
0248.
[
0249.
SRCategory(SR.CatAppearance),
0250.
SRDescription(SR.DateTimePickerCalendarTrailingForeColorDescr)
0251.
]
0252.
public
Color CalendarTrailingForeColor {
0253.
get
{
0254.
return
calendarTrailingText;
0255.
}
0256.
0257.
set
{
0258.
if
(value.IsEmpty) {
0259.
throw
new
ArgumentException(SR.GetString(SR.InvalidNullArgument,
0260.
"value"
));
0261.
}
0262.
if
(!value.Equals(calendarTrailingText)) {
0263.
calendarTrailingText = value;
0264.
SetControlColor(NativeMethods.MCSC_TRAILINGTEXT, value);
0265.
}
0266.
}
0267.
}
0268.
0269.
0270.
[
0271.
SRCategory(SR.CatAppearance),
0272.
SRDescription(SR.DateTimePickerCalendarMonthBackgroundDescr)
0273.
]
0274.
public
Color CalendarMonthBackground {
0275.
get
{
0276.
return
calendarMonthBackground;
0277.
}
0278.
0279.
set
{
0280.
if
(value.IsEmpty) {
0281.
throw
new
ArgumentException(SR.GetString(SR.InvalidNullArgument,
0282.
"value"
));
0283.
}
0284.
if
(!value.Equals(calendarMonthBackground)) {
0285.
calendarMonthBackground = value;
0286.
SetControlColor(NativeMethods.MCSC_MONTHBK, value);
0287.
}
0288.
}
0289.
}
0290.
0291.
0292.
[
0293.
SRCategory(SR.CatBehavior),
0294.
DefaultValue(
true
),
0295.
Bindable(
true
),
0296.
SRDescription(SR.DateTimePickerCheckedDescr)
0297.
]
0298.
public
bool
Checked {
0299.
get
{
0300.
0301.
if
(
this
.ShowCheckBox && IsHandleCreated) {
0302.
NativeMethods.SYSTEMTIME sys =
new
NativeMethods.SYSTEMTIME();
0303.
int
gdt = (
int
)UnsafeNativeMethods.SendMessage(
new
HandleRef(
this
, Handle), NativeMethods.DTM_GETSYSTEMTIME, 0, sys);
0304.
return
gdt == NativeMethods.GDT_VALID;
0305.
}
else
{
0306.
return
validTime;
0307.
}
0308.
}
0309.
set
{
0310.
if
(
this
.Checked != value) {
0311.
0312.
if
(
this
.ShowCheckBox && IsHandleCreated) {
0313.
if
(value) {
0314.
int
gdt = NativeMethods.GDT_VALID;
0315.
NativeMethods.SYSTEMTIME sys = DateTimePicker.DateTimeToSysTime(Value);
0316.
UnsafeNativeMethods.SendMessage(
new
HandleRef(
this
, Handle), NativeMethods.DTM_SETSYSTEMTIME, gdt, sys);
0317.
}
0318.
else
{
0319.
int
gdt = NativeMethods.GDT_NONE;
0320.
NativeMethods.SYSTEMTIME sys =
null
;
0321.
UnsafeNativeMethods.SendMessage(
new
HandleRef(
this
, Handle), NativeMethods.DTM_SETSYSTEMTIME, gdt, sys);
0322.
}
0323.
}
0324.
0325.
0326.
0327.
this
.validTime = value;
0328.
}
0329.
}
0330.
}
0331.
0332.
[
0333.
Browsable(
false
),
0334.
EditorBrowsable(EditorBrowsableState.Never)
0335.
]
0336.
new
public
event
EventHandler Click {
0337.
add {
base
.Click += value; }
0338.
remove {
base
.Click -= value; }
0339.
}
0340.
0341.
0342.
protected
override
CreateParams CreateParams {
0343.
[SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)]
0344.
get
{
0345.
CreateParams cp =
base
.CreateParams;
0346.
cp.ClassName = NativeMethods.WC_DATETIMEPICK;
0347.
0348.
cp.Style |= style;
0349.
0350.
switch
(format) {
0351.
case
DateTimePickerFormat.Long:
0352.
cp.Style |= NativeMethods.DTS_LONGDATEFORMAT;
0353.
break
;
0354.
case
DateTimePickerFormat.Short:
0355.
break
;
0356.
case
DateTimePickerFormat.Time:
0357.
cp.Style |= TIMEFORMAT_NOUPDOWN;
0358.
break
;
0359.
case
DateTimePickerFormat.Custom:
0360.
break
;
0361.
}
0362.
0363.
cp.ExStyle |= NativeMethods.WS_EX_CLIENTEDGE;
0364.
0365.
if
(RightToLeft == RightToLeft.Yes && RightToLeftLayout ==
true
) {
0366.
0367.
cp.ExStyle |= NativeMethods.WS_EX_LAYOUTRTL;
0368.
0369.
cp.ExStyle &= ~(NativeMethods.WS_EX_RTLREADING | NativeMethods.WS_EX_RIGHT | NativeMethods.WS_EX_LEFTSCROLLBAR);
0370.
}
0371.
0372.
return
cp;
0373.
}
0374.
}
0375.
0376.
0377.
[
0378.
DefaultValue(
null
),
0379.
Localizable(
true
),
0380.
RefreshProperties(RefreshProperties.Repaint),
0381.
SRCategory(SR.CatBehavior),
0382.
SRDescription(SR.DateTimePickerCustomFormatDescr)
0383.
]
0384.
public
string
CustomFormat {
0385.
get
{
0386.
return
customFormat;
0387.
}
0388.
0389.
set
{
0390.
if
((value !=
null
&& !value.Equals(customFormat)) ||
0391.
(value ==
null
&& customFormat !=
null
)) {
0392.
0393.
customFormat = value;
0394.
0395.
if
(IsHandleCreated) {
0396.
if
(format == DateTimePickerFormat.Custom)
0397.
SendMessage(NativeMethods.DTM_SETFORMAT, 0, customFormat);
0398.
}
0399.
}
0400.
}
0401.
}
0402.
0403.
0404.
protected
override
Size DefaultSize {
0405.
get
{
0406.
return
new
Size(200, PreferredHeight);
0407.
}
0408.
}
0409.
0410.
0411.
[EditorBrowsable(EditorBrowsableState.Never)]
0412.
protected
override
bool
DoubleBuffered {
0413.
get
{
0414.
return
base
.DoubleBuffered;
0415.
}
0416.
set
{
0417.
base
.DoubleBuffered = value;
0418.
}
0419.
}
0420.
0421.
[
0422.
Browsable(
false
),
0423.
EditorBrowsable(EditorBrowsableState.Never)
0424.
]
0425.
new
public
event
EventHandler DoubleClick {
0426.
add {
base
.DoubleClick += value; }
0427.
remove {
base
.DoubleClick -= value; }
0428.
}
0429.
0430.
0431.
[
0432.
DefaultValue(LeftRightAlignment.Left),
0433.
SRCategory(SR.CatAppearance),
0434.
Localizable(
true
),
0435.
SRDescription(SR.DateTimePickerDropDownAlignDescr)
0436.
]
0437.
public
LeftRightAlignment DropDownAlign {
0438.
get
{
0439.
return
((style & NativeMethods.DTS_RIGHTALIGN) != 0)
0440.
? LeftRightAlignment.Right
0441.
: LeftRightAlignment.Left;
0442.
}
0443.
0444.
set
{
0445.
0446.
if
(!ClientUtils.IsEnumValid(value, (
int
)value, (
int
)LeftRightAlignment.Left, (
int
)LeftRightAlignment.Right)){
0447.
throw
new
InvalidEnumArgumentException(
"value"
, (
int
)value,
typeof
(LeftRightAlignment));
0448.
}
0449.
0450.
SetStyleBit((value == LeftRightAlignment.Right), NativeMethods.DTS_RIGHTALIGN);
0451.
}
0452.
}
0453.
0454.
0455.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0456.
public
override
Color ForeColor {
0457.
get
{
0458.
if
(ShouldSerializeForeColor()) {
0459.
return
base
.ForeColor;
0460.
}
0461.
else
{
0462.
return
SystemColors.WindowText;
0463.
}
0464.
}
0465.
set
{
0466.
base
.ForeColor = value;
0467.
}
0468.
}
0469.
0470.
0471.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0472.
new
public
event
EventHandler ForeColorChanged {
0473.
add {
0474.
base
.ForeColorChanged += value;
0475.
}
0476.
remove {
0477.
base
.ForeColorChanged -= value;
0478.
}
0479.
}
0480.
0481.
0482.
[
0483.
SRCategory(SR.CatAppearance),
0484.
RefreshProperties(RefreshProperties.Repaint),
0485.
SRDescription(SR.DateTimePickerFormatDescr)
0486.
]
0487.
public
DateTimePickerFormat Format {
0488.
get
{
0489.
return
format;
0490.
}
0491.
0492.
set
{
0493.
0494.
if
(!ClientUtils.IsEnumValid(value, (
int
)value, (
int
)DateTimePickerFormat.Long, (
int
)DateTimePickerFormat.Custom,
1))
0495.
{
0496.
throw
new
InvalidEnumArgumentException(
"value"
, (
int
)value,
typeof
(DateTimePickerFormat));
0497.
}
0498.
0499.
if
(format != value) {
0500.
0501.
format = value;
0502.
RecreateHandle();
0503.
0504.
OnFormatChanged(EventArgs.Empty);
0505.
}
0506.
}
0507.
}
0508.
0509.
0510.
[SRCategory(SR.CatPropertyChanged), SRDescription(SR.DateTimePickerOnFormatChangedDescr)]
0511.
public
event
EventHandler FormatChanged {
0512.
add {
0513.
Events.AddHandler(EVENT_FORMATCHANGED, value);
0514.
}
0515.
remove {
0516.
Events.RemoveHandler(EVENT_FORMATCHANGED, value);
0517.
}
0518.
}
0519.
0520.
0521.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Never)]
0522.
public
new
event
PaintEventHandler Paint {
0523.
add {
0524.
base
.Paint += value;
0525.
}
0526.
remove {
0527.
base
.Paint -= value;
0528.
}
0529.
}
0530.
0531.
0532.
static
internal
DateTime EffectiveMinDate(DateTime minDate)
0533.
{
0534.
DateTime minSupportedDate = DateTimePicker.MinimumDateTime;
0535.
if
(minDate < minSupportedDate)
0536.
{
0537.
return
minSupportedDate;
0538.
}
0539.
return
minDate;
0540.
}
0541.
0542.
0543.
static
internal
DateTime EffectiveMaxDate(DateTime maxDate)
0544.
{
0545.
DateTime maxSupportedDate = DateTimePicker.MaximumDateTime;
0546.
if
(maxDate > maxSupportedDate)
0547.
{
0548.
return
maxSupportedDate;
0549.
}
0550.
return
maxDate;
0551.
}
0552.
0553.
0554.
0555.
0556.
[
0557.
SRCategory(SR.CatBehavior),
0558.
SRDescription(SR.DateTimePickerMaxDateDescr)
0559.
]
0560.
public
DateTime MaxDate {
0561.
get
{
0562.
return
EffectiveMaxDate(max);
0563.
}
0564.
set
{
0565.
if
(value != max) {
0566.
if
(value < EffectiveMinDate(min))
0567.
{
0568.
throw
new
ArgumentOutOfRangeException(
"MaxDate"
, SR.GetString(SR.InvalidLowBoundArgumentEx,
"MaxDate"
, FormatDateTime(value),
"MinDate"
));
0569.
}
0570.
0571.
0572.
if
(value > MaximumDateTime) {
0573.
throw
new
ArgumentOutOfRangeException(
"MaxDate"
, SR.GetString(SR.DateTimePickerMaxDate, FormatDateTime(DateTimePicker.MaxDateTime)));
0574.
}
0575.
0576.
max = value;
0577.
SetRange();
0578.
0579.
0580.
0581.
if
(Value > max) {
0582.
Value = max;
0583.
}
0584.
}
0585.
}
0586.
}
0587.
0588.
0589.
public
static
DateTime MaximumDateTime {
0590.
get
{
0591.
DateTime maxSupportedDateTime = CultureInfo.CurrentCulture.Calendar.MaxSupportedDateTime;
0592.
if
(maxSupportedDateTime.Year > MaxDateTime.Year)
0593.
{
0594.
return
MaxDateTime;
0595.
}
0596.
return
maxSupportedDateTime;
0597.
}
0598.
}
0599.
0600.
0601.
[
0602.
SRCategory(SR.CatBehavior),
0603.
SRDescription(SR.DateTimePickerMinDateDescr)
0604.
]
0605.
public
DateTime MinDate {
0606.
get
{
0607.
return
EffectiveMinDate(min);
0608.
}
0609.
set
0610.
{
0611.
if
(value != min)
0612.
{
0613.
if
(value > EffectiveMaxDate(max))
0614.
{
0615.
throw
new
ArgumentOutOfRangeException(
"MinDate"
, SR.GetString(SR.InvalidHighBoundArgument,
"MinDate"
, FormatDateTime(value),
"MaxDate"
));
0616.
}
0617.
0618.
0619.
if
(value < MinimumDateTime)
0620.
{
0621.
throw
new
ArgumentOutOfRangeException(
"MinDate"
, SR.GetString(SR.DateTimePickerMinDate, FormatDateTime(DateTimePicker.MinimumDateTime)));
0622.
}
0623.
0624.
min = value;
0625.
SetRange();
0626.
0627.
0628.
0629.
if
(Value < min)
0630.
{
0631.
Value = min;
0632.
}
0633.
}
0634.
}
0635.
}
0636.
0637.
0638.
public
static
DateTime MinimumDateTime {
0639.
get
{
0640.
DateTime minSupportedDateTime = CultureInfo.CurrentCulture.Calendar.MinSupportedDateTime;
0641.
if
(minSupportedDateTime.Year < 1753)
0642.
{
0643.
return
new
DateTime(1753, 1, 1);
0644.
}
0645.
return
minSupportedDateTime;
0646.
}
0647.
}
0648.
0649.
[
0650.
Browsable(
false
),
0651.
EditorBrowsable(EditorBrowsableState.Never)
0652.
]
0653.
new
public
event
MouseEventHandler MouseClick {
0654.
add {
base
.MouseClick += value; }
0655.
remove {
base
.MouseClick -= value; }
0656.
}
0657.
0658.
[
0659.
Browsable(
false
),
0660.
EditorBrowsable(EditorBrowsableState.Never)
0661.
]
0662.
new
public
event
MouseEventHandler MouseDoubleClick {
0663.
add {
base
.MouseDoubleClick += value; }
0664.
remove {
base
.MouseDoubleClick -= value; }
0665.
}
0666.
0667.
0668.
[
0669.
Browsable(
false
),
0670.
EditorBrowsable(EditorBrowsableState.Never),
0671.
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
0672.
]
0673.
public
new
Padding Padding {
0674.
get
{
return
base
.Padding; }
0675.
set
{
base
.Padding = value;}
0676.
}
0677.
0678.
[
0679.
Browsable(
false
),
0680.
EditorBrowsable(EditorBrowsableState.Never)
0681.
]
0682.
public
new
event
EventHandler PaddingChanged {
0683.
add {
base
.PaddingChanged += value; }
0684.
remove {
base
.PaddingChanged -= value; }
0685.
}
0686.
0687.
0688.
[
0689.
Browsable(
false
),
0690.
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
0691.
]
0692.
public
int
PreferredHeight {
0693.
get
{
0694.
if
(prefHeightCache > -1)
0695.
return
(
int
)prefHeightCache;
0696.
0697.
0698.
int
height = FontHeight;
0699.
0700.
0701.
height += SystemInformation.BorderSize.Height * 4 + 3;
0702.
prefHeightCache = (
short
)height;
0703.
0704.
return
height;
0705.
}
0706.
}
0707.
0708.
0709.
[
0710.
SRCategory(SR.CatAppearance),
0711.
Localizable(
true
),
0712.
DefaultValue(
false
),
0713.
SRDescription(SR.ControlRightToLeftLayoutDescr)
0714.
]
0715.
public
virtual
bool
RightToLeftLayout {
0716.
get
{
0717.
0718.
return
rightToLeftLayout;
0719.
}
0720.
0721.
set
{
0722.
if
(value != rightToLeftLayout) {
0723.
rightToLeftLayout = value;
0724.
using
(
new
LayoutTransaction(
this
,
this
, PropertyNames.RightToLeftLayout)) {
0725.
OnRightToLeftLayoutChanged(EventArgs.Empty);
0726.
}
0727.
}
0728.
}
0729.
}
0730.
0731.
0732.
0733.
0734.
[
0735.
DefaultValue(
false
),
0736.
SRCategory(SR.CatAppearance),
0737.
SRDescription(SR.DateTimePickerShowNoneDescr)
0738.
]
0739.
public
bool
ShowCheckBox {
0740.
get
{
0741.
return
(style & NativeMethods.DTS_SHOWNONE) != 0;
0742.
}
0743.
set
{
0744.
SetStyleBit(value, NativeMethods.DTS_SHOWNONE);
0745.
}
0746.
}
0747.
0748.
0749.
[
0750.
DefaultValue(
false
),
0751.
SRCategory(SR.CatAppearance),
0752.
SRDescription(SR.DateTimePickerShowUpDownDescr)
0753.
]
0754.
public
bool
ShowUpDown {
0755.
get
{
0756.
return
(style & NativeMethods.DTS_UPDOWN) != 0;
0757.
}
0758.
set
{
0759.
if
(ShowUpDown != value) {
0760.
SetStyleBit(value, NativeMethods.DTS_UPDOWN);
0761.
}
0762.
}
0763.
}
0764.
0765.
0766.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Advanced), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
0767.
public
override
string
Text {
0768.
get
{
0769.
return
base
.Text;
0770.
}
0771.
set
{
0772.
0773.
0774.
if
(value ==
null
|| value.Length == 0) {
0775.
ResetValue();
0776.
}
0777.
else
{
0778.
Value = DateTime.Parse(value, CultureInfo.CurrentCulture);
0779.
}
0780.
}
0781.
}
0782.
0783.
0784.
[Browsable(
false
), EditorBrowsable(EditorBrowsableState.Advanced)]
0785.
new
public
event
EventHandler TextChanged {
0786.
add {
0787.
base
.TextChanged += value;
0788.
}
0789.
remove {
0790.
base
.TextChanged -= value;
0791.
}
0792.
}
0793.
0794.
0795.
[
0796.
SRCategory(SR.CatBehavior),
0797.
Bindable(
true
),
0798.
RefreshProperties(RefreshProperties.All),
0799.
SRDescription(SR.DateTimePickerValueDescr)
0800.
]
0801.
public
DateTime Value {
0802.
get
{
0803.
0804.
if
(!userHasSetValue && validTime)
0805.
return
creationTime;
0806.
else
0807.
return
value;
0808.
}
0809.
set
{
0810.
bool
valueChanged = !DateTime.Equals(
this
.Value, value);
0811.
0812.
if
(!userHasSetValue || valueChanged) {
0813.
if
((value < MinDate) || (value > MaxDate)) {
0814.
throw
new
ArgumentOutOfRangeException(
"Value"
, SR.GetString(SR.InvalidBoundArgument,
"Value"
, FormatDateTime(value),
"'MinDate'"
,
"'MaxDate'"
));
0815.
}
0816.
0817.
string
oldText =
this
.Text;
0818.
0819.
this
.value = value;
0820.
userHasSetValue =
true
;
0821.
0822.
if
(IsHandleCreated) {
0823.
0824.
0825.
0826.
0827.
int
gdt = NativeMethods.GDT_VALID;
0828.
NativeMethods.SYSTEMTIME sys = DateTimePicker.DateTimeToSysTime(value);
0829.
UnsafeNativeMethods.SendMessage(
new
HandleRef(
this
, Handle), NativeMethods.DTM_SETSYSTEMTIME, gdt, sys);
0830.
}
0831.
0832.
if
(valueChanged) {
0833.
OnValueChanged(EventArgs.Empty);
0834.
}
0835.
0836.
if
(!oldText.Equals(
this
.Text)) {
0837.
OnTextChanged(EventArgs.Empty);
0838.
}
0839.
}
0840.
}
0841.
}
0842.
0843.
0844.
[SRCategory(SR.CatAction), SRDescription(SR.DateTimePickerOnCloseUpDescr)]
0845.
public
event
EventHandler CloseUp {
0846.
add {
0847.
onCloseUp += value;
0848.
}
0849.
remove {
0850.
onCloseUp -= value;
0851.
}
0852.
}
0853.
0854.
0855.
0856.
[SRCategory(SR.CatPropertyChanged), SRDescription(SR.ControlOnRightToLeftLayoutChangedDescr)]
0857.
public
event
EventHandler RightToLeftLayoutChanged {
0858.
add {
0859.
onRightToLeftLayoutChanged += value;
0860.
}
0861.
remove {
0862.
onRightToLeftLayoutChanged -= value;
0863.
}
0864.
}
0865.
0866.
0867.
[SRCategory(SR.CatAction), SRDescription(SR.valueChangedEventDescr)]
0868.
public
event
EventHandler ValueChanged {
0869.
add {
0870.
onValueChanged += value;
0871.
}
0872.
remove {
0873.
onValueChanged -= value;
0874.
}
0875.
}
0876.
0877.
0878.
0879.
[SRCategory(SR.CatAction), SRDescription(SR.DateTimePickerOnDropDownDescr)]
0880.
public
event
EventHandler DropDown {
0881.
add {
0882.
onDropDown += value;
0883.
}
0884.
remove {
0885.
onDropDown -= value;
0886.
}
0887.
}
0888.
0889.
0890.
protected
override
AccessibleObject CreateAccessibilityInstance() {
0891.
return
new
DateTimePickerAccessibleObject(
this
);
0892.
}
0893.
0894.
0895.
protected
override
void
CreateHandle() {
0896.
if
(!RecreatingHandle) {
0897.
IntPtr userCookie = UnsafeNativeMethods.ThemingScope.Activate();
0898.
0899.
try
{
0900.
NativeMethods.INITCOMMONCONTROLSEX icc =
new
NativeMethods.INITCOMMONCONTROLSEX();
0901.
icc.dwICC = NativeMethods.ICC_DATE_CLASSES;
0902.
SafeNativeMethods.InitCommonControlsEx(icc);
0903.
}
0904.
finally
{
0905.
UnsafeNativeMethods.ThemingScope.Deactivate(userCookie);
0906.
}
0907.
}
0908.
0909.
creationTime = DateTime.Now;
0910.
0911.
base
.CreateHandle();
0912.
0913.
if
(userHasSetValue && validTime) {
0914.
0915.
0916.
0917.
0918.
int
gdt = NativeMethods.GDT_VALID;
0919.
NativeMethods.SYSTEMTIME sys = DateTimePicker.DateTimeToSysTime(Value);
0920.
UnsafeNativeMethods.SendMessage(
new
HandleRef(
this
, Handle), NativeMethods.DTM_SETSYSTEMTIME, gdt, sys);
0921.
}
0922.
else
if
(!validTime) {
0923.
int
gdt = NativeMethods.GDT_NONE;
0924.
NativeMethods.SYSTEMTIME sys =
null
;
0925.
UnsafeNativeMethods.SendMessage(
new
HandleRef(
this
, Handle), NativeMethods.DTM_SETSYSTEMTIME, gdt, sys);
0926.
}
0927.
0928.
if
(format == DateTimePickerFormat.Custom) {
0929.
SendMessage(NativeMethods.DTM_SETFORMAT, 0, customFormat);
0930.
}
0931.
0932.
UpdateUpDown();
0933.
SetAllControlColors();
0934.
SetControlCalendarFont();
0935.
SetRange();
0936.
}
0937.
0938.
0939.
[UIPermission(SecurityAction.LinkDemand, Window=UIPermissionWindow.AllWindows)]
0940.
protected
override
void
DestroyHandle() {
0941.
value = Value;
0942.
base
.DestroyHandle();
0943.
}
0944.
0945.
0946.
0947.
0948.
private
static
string
FormatDateTime(DateTime value) {
0949.
return
value.ToString(
"G"
, CultureInfo.CurrentCulture);
0950.
}
0951.
0952.
0953.
0954.
internal
override
Rectangle ApplyBoundsConstraints(
int
suggestedX,
int
suggestedY,
int
proposedWidth,
int
proposedHeight) {
0955.
0956.
return
base
.ApplyBoundsConstraints(suggestedX,suggestedY, proposedWidth, PreferredHeight);
0957.
}
0958.
0959.
internal
override
Size GetPreferredSizeCore(Size proposedConstraints) {
0960.
int
height = PreferredHeight;
0961.
int
width = CommonProperties.GetSpecifiedBounds(
this
).Width;
0962.
return
new
Size(width, height);
0963.
}
0964.
0965.
0966.
0967.
protected
override
bool
IsInputKey(Keys keyData) {
0968.
if
((keyData & Keys.Alt) == Keys.Alt)
return
false
;
0969.
switch
(keyData & Keys.KeyCode) {
0970.
case
Keys.PageUp:
0971.
case
Keys.PageDown:
0972.
case
Keys.Home:
0973.
case
Keys.End:
0974.
return
true
;
0975.
}
0976.
return
base
.IsInputKey(keyData);
0977.
}
0978.
0979.
0980.
protected
virtual
void
OnCloseUp(EventArgs eventargs) {
0981.
if
(onCloseUp !=
null
) onCloseUp(
this
, eventargs);
0982.
}
0983.
0984.
0985.
protected
virtual
void
OnDropDown(EventArgs eventargs) {
0986.
if
(onDropDown !=
null
) {
0987.
onDropDown(
this
, eventargs);
0988.
}
0989.
}
0990.
0991.
0992.
protected
virtual
void
OnFormatChanged(EventArgs e) {
0993.
EventHandler eh = Events[EVENT_FORMATCHANGED]
as
EventHandler;
0994.
if
(eh !=
null
) {
0995.
eh(
this
, e);
0996.
}
0997.
}
0998.
0999.
1000.
1001.
protected
override
void
OnHandleCreated(EventArgs e)
1002.
{
1003.
base
.OnHandleCreated(e);
1004.
SystemEvents.UserPreferenceChanged +=
new
UserPreferenceChangedEventHandler(
this
.MarshaledUserPreferenceChanged);
1005.
}
1006.
1007.
1008.
protected
override
void
OnHandleDestroyed(EventArgs e)
1009.
{
1010.
SystemEvents.UserPreferenceChanged -=
new
UserPreferenceChangedEventHandler(
this
.MarshaledUserPreferenceChanged);
1011.
base
.OnHandleDestroyed(e);
1012.
}
1013.
1014.
1015.
protected
virtual
void
OnValueChanged(EventArgs eventargs) {
1016.
if
(onValueChanged !=
null
) {
1017.
onValueChanged(
this
, eventargs);
1018.
}
1019.
}
1020.
1021.
1022.
[EditorBrowsable(EditorBrowsableState.Advanced)]
1023.
protected
virtual
void
OnRightToLeftLayoutChanged(EventArgs e) {
1024.
if
(GetAnyDisposingInHierarchy()) {
1025.
return
;
1026.
}
1027.
1028.
if
(RightToLeft == RightToLeft.Yes) {
1029.
RecreateHandle();
1030.
}
1031.
1032.
if
(onRightToLeftLayoutChanged !=
null
) {
1033.
onRightToLeftLayoutChanged(
this
, e);
1034.
}
1035.
}
1036.
1037.
1038.
1039.
protected
override
void
OnFontChanged(EventArgs e) {
1040.
base
.OnFontChanged(e);
1041.
1042.
1043.
prefHeightCache = -1;
1044.
1045.
Height = PreferredHeight;
1046.
1047.
if
(calendarFont ==
null
) {
1048.
calendarFontHandleWrapper =
null
;
1049.
SetControlCalendarFont();
1050.
}
1051.
}
1052.
1053.
private
void
ResetCalendarForeColor() {
1054.
CalendarForeColor = DefaultForeColor;
1055.
}
1056.
1057.
private
void
ResetCalendarFont() {
1058.
CalendarFont =
null
;
1059.
}
1060.
1061.
private
void
ResetCalendarMonthBackground() {
1062.
CalendarMonthBackground = DefaultMonthBackColor;
1063.
}
1064.
1065.
private
void
ResetCalendarTitleBackColor() {
1066.
CalendarTitleBackColor = DefaultTitleBackColor;
1067.
}
1068.
1069.
private
void
ResetCalendarTitleForeColor() {
1070.
CalendarTitleBackColor = DefaultForeColor;
1071.
}
1072.
1073.
private
void
ResetCalendarTrailingForeColor() {
1074.
CalendarTrailingForeColor = DefaultTrailingForeColor;
1075.
}
1076.
1077.
1078.
private
void
ResetFormat() {
1079.
Format = DateTimePickerFormat.Long;
1080.
}
1081.
1082.
1083.
private
void
ResetMaxDate() {
1084.
MaxDate = MaximumDateTime;
1085.
}
1086.
1087.
1088.
private
void
ResetMinDate() {
1089.
MinDate = MinimumDateTime;
1090.
}
1091.
1092.
1093.
private
void
ResetValue() {
1094.
1095.
1096.
this
.value = DateTime.Now;
1097.
1098.
1099.
userHasSetValue =
false
;
1100.
1101.
1102.
if
(IsHandleCreated) {
1103.
int
gdt = NativeMethods.GDT_VALID;
1104.
NativeMethods.SYSTEMTIME sys = DateTimePicker.DateTimeToSysTime(value);
1105.
UnsafeNativeMethods.SendMessage(
new
HandleRef(
this
, Handle), NativeMethods.DTM_SETSYSTEMTIME, gdt, sys);
1106.
}
1107.
1108.
1109.
1110.
Checked =
false
;
1111.
1112.
OnValueChanged(EventArgs.Empty);
1113.
OnTextChanged(EventArgs.Empty);
1114.
}
1115.
1116.
1117.
private
void
SetControlColor(
int
colorIndex, Color value) {
1118.
if
(IsHandleCreated) {
1119.
SendMessage(NativeMethods.DTM_SETMCCOLOR, colorIndex, ColorTranslator.ToWin32(value));
1120.
}
1121.
}
1122.
1123.
1124.
private
void
SetControlCalendarFont() {
1125.
if
(IsHandleCreated) {
1126.
SendMessage(NativeMethods.DTM_SETMCFONT, CalendarFontHandle, NativeMethods.InvalidIntPtr);
1127.
}
1128.
}
1129.
1130.
1131.
private
void
SetAllControlColors() {
1132.
SetControlColor(NativeMethods.MCSC_MONTHBK, calendarMonthBackground);
1133.
SetControlColor(NativeMethods.MCSC_TEXT, calendarForeColor);
1134.
SetControlColor(NativeMethods.MCSC_TITLEBK, calendarTitleBackColor);
1135.
SetControlColor(NativeMethods.MCSC_TITLETEXT, calendarTitleForeColor);
1136.
SetControlColor(NativeMethods.MCSC_TRAILINGTEXT, calendarTrailingText);
1137.
}
1138.
1139.
1140.
private
void
SetRange() {
1141.
SetRange(EffectiveMinDate(min), EffectiveMaxDate(max));
1142.
}
1143.
1144.
private
void
SetRange(DateTime min, DateTime max) {
1145.
if
(IsHandleCreated) {
1146.
int
flags = 0;
1147.
1148.
NativeMethods.SYSTEMTIMEARRAY sa =
new
NativeMethods.SYSTEMTIMEARRAY();
1149.
1150.
flags |= NativeMethods.GDTR_MIN | NativeMethods.GDTR_MAX;
1151.
NativeMethods.SYSTEMTIME sys = DateTimePicker.DateTimeToSysTime(min);
1152.
sa.wYear1 = sys.wYear;
1153.
sa.wMonth1 = sys.wMonth;
1154.
sa.wDayOfWeek1 = sys.wDayOfWeek;
1155.
sa.wDay1 = sys.wDay;
1156.
sa.wHour1 = sys.wHour;
1157.
sa.wMinute1 = sys.wMinute;
1158.
sa.wSecond1 = sys.wSecond;
1159.
sa.wMilliseconds1 = sys.wMilliseconds;
1160.
sys = DateTimePicker.DateTimeToSysTime(max);
1161.
sa.wYear2 = sys.wYear;
1162.
sa.wMonth2 = sys.wMonth;
1163.
sa.wDayOfWeek2 = sys.wDayOfWeek;
1164.
sa.wDay2 = sys.wDay;
1165.
sa.wHour2 = sys.wHour;
1166.
sa.wMinute2 = sys.wMinute;
1167.
sa.wSecond2 = sys.wSecond;
1168.
sa.wMilliseconds2 = sys.wMilliseconds;
1169.
UnsafeNativeMethods.SendMessage(
new
HandleRef(
this
, Handle), NativeMethods.DTM_SETRANGE, flags, sa);
1170.
}
1171.
}
1172.
1173.
1174.
private
void
SetStyleBit(
bool
flag,
int
bit) {
1175.
if
(((style & bit) != 0) == flag)
return
;
1176.
1177.
if
(flag) {
1178.
style |= bit;
1179.
}
1180.
else
{
1181.
style &= ~bit;
1182.
}
1183.
1184.
if
(IsHandleCreated) {
1185.
RecreateHandle();
1186.
Invalidate();
1187.
Update();
1188.
}
1189.
}
1190.
1191.
1192.
private
bool
ShouldSerializeCalendarForeColor() {
1193.
return
!CalendarForeColor.Equals(DefaultForeColor);
1194.
}
1195.
1196.
1197.
private
bool
ShouldSerializeCalendarFont() {
1198.
return
calendarFont !=
null
;
1199.
}
1200.
1201.
1202.
private
bool
ShouldSerializeCalendarTitleBackColor() {
1203.
return
!calendarTitleBackColor.Equals(DefaultTitleBackColor);
1204.
}
1205.
1206.
1207.
private
bool
ShouldSerializeCalendarTitleForeColor() {
1208.
return
!calendarTitleForeColor.Equals(DefaultTitleForeColor);
1209.
}
1210.
1211.
1212.
private
bool
ShouldSerializeCalendarTrailingForeColor() {
1213.
return
!calendarTrailingText.Equals(DefaultTrailingForeColor);
1214.
}
1215.
1216.
1217.
private
bool
ShouldSerializeCalendarMonthBackground() {
1218.
return
!calendarMonthBackground.Equals(DefaultMonthBackColor);
1219.
}
1220.
1221.
1222.
private
bool
ShouldSerializeMaxDate() {
1223.
return
max != MaximumDateTime && max != DateTime.MaxValue;
1224.
}
1225.
1226.
1227.
private
bool
ShouldSerializeMinDate() {
1228.
return
min != MinimumDateTime && min != DateTime.MinValue;
1229.
}
1230.
1231.
1232.
private
bool
ShouldSerializeValue() {
1233.
return
userHasSetValue;
1234.
}
1235.
1236.
1237.
private
bool
ShouldSerializeFormat() {
1238.
return
(Format != DateTimePickerFormat.Long);
1239.
}
1240.
1241.
1242.
public
override
string
ToString() {
1243.
1244.
string
s =
base
.ToString();
1245.
return
s +
", Value: "
+ FormatDateTime(Value);
1246.
}
1247.
1248.
1249.
private
void
UpdateUpDown() {
1250.
1251.
1252.
if
(ShowUpDown) {
1253.
EnumChildren c =
new
EnumChildren();
1254.
NativeMethods.EnumChildrenCallback cb =
new
NativeMethods.EnumChildrenCallback(c.enumChildren);
1255.
UnsafeNativeMethods.EnumChildWindows(
new
HandleRef(
this
, Handle), cb, NativeMethods.NullHandleRef);
1256.
if
(c.hwndFound != IntPtr.Zero) {
1257.
SafeNativeMethods.InvalidateRect(
new
HandleRef(c, c.hwndFound),
null
,
true
);
1258.
SafeNativeMethods.UpdateWindow(
new
HandleRef(c, c.hwndFound));
1259.
}
1260.
}
1261.
}
1262.
1263.
private
void
MarshaledUserPreferenceChanged(
object
sender, UserPreferenceChangedEventArgs pref) {
1264.
try
{
1265.
1266.
BeginInvoke(
new
UserPreferenceChangedEventHandler(
this
.UserPreferenceChanged),
new
object
[] { sender, pref });
1267.
}
1268.
catch
(InvalidOperationException) { }
1269.
}
1270.
1271.
private
void
UserPreferenceChanged(
object
sender, UserPreferenceChangedEventArgs pref) {
1272.
if
(pref.Category == UserPreferenceCategory.Locale) {
1273.
1274.
1275.
1276.
RecreateHandle();
1277.
}
1278.
}
1279.
1280.
1281.
private
void
WmCloseUp(
ref
Message m) {
1282.
OnCloseUp(EventArgs.Empty);
1283.
}
1284.
1285.
1286.
private
void
WmDateTimeChange(
ref
Message m) {
1287.
NativeMethods.NMDATETIMECHANGE nmdtc = (NativeMethods.NMDATETIMECHANGE)m.GetLParam(
typeof
(NativeMethods.NMDATETIMECHANGE));
1288.
DateTime temp = value;
1289.
bool
oldvalid = validTime;
1290.
if
(nmdtc.dwFlags != NativeMethods.GDT_NONE) {
1291.
validTime =
true
;
1292.
value = DateTimePicker.SysTimeToDateTime(nmdtc.st);
1293.
userHasSetValue =
true
;
1294.
}
1295.
else
{
1296.
validTime =
false
;
1297.
}
1298.
if
(value!=temp || oldvalid != validTime) {
1299.
OnValueChanged(EventArgs.Empty);
1300.
OnTextChanged(EventArgs.Empty);
1301.
}
1302.
}
1303.
1304.
1305.
private
void
WmDropDown(
ref
Message m) {
1306.
1307.
if
(
this
.RightToLeftLayout ==
true
&&
this
.RightToLeft == RightToLeft.Yes) {
1308.
IntPtr handle = SendMessage(NativeMethods.DTM_GETMONTHCAL, 0,0);
1309.
if
(handle != IntPtr.Zero) {
1310.
int
style =
unchecked
((
int
)((
long
)UnsafeNativeMethods.GetWindowLong(
new
HandleRef(
this
, handle), NativeMethods.GWL_EXSTYLE)));
1311.
style |= NativeMethods.WS_EX_LAYOUTRTL | NativeMethods.WS_EX_NOINHERITLAYOUT;
1312.
style &= ~(NativeMethods.WS_EX_RIGHT | NativeMethods.WS_EX_RTLREADING);
1313.
UnsafeNativeMethods.SetWindowLong(
new
HandleRef(
this
, handle), NativeMethods.GWL_EXSTYLE,
new
HandleRef(
this
, (IntPtr)style));
1314.
}
1315.
}
1316.
OnDropDown(EventArgs.Empty);
1317.
}
1318.
1319.
1320.
protected
override
void
OnSystemColorsChanged(EventArgs e) {
1321.
SetAllControlColors();
1322.
base
.OnSystemColorsChanged(e);
1323.
}
1324.
1325.
1326.
private
void
WmReflectCommand(
ref
Message m) {
1327.
if
(m.HWnd == Handle) {
1328.
1329.
NativeMethods.NMHDR nmhdr = (NativeMethods.NMHDR)m.GetLParam(
typeof
(NativeMethods.NMHDR));
1330.
switch
(nmhdr.code) {
1331.
case
NativeMethods.DTN_CLOSEUP:
1332.
WmCloseUp(
ref
m);
1333.
break
;
1334.
case
NativeMethods.DTN_DATETIMECHANGE:
1335.
WmDateTimeChange(
ref
m);
1336.
break
;
1337.
case
NativeMethods.DTN_DROPDOWN:
1338.
WmDropDown(
ref
m);
1339.
break
;
1340.
}
1341.
}
1342.
}
1343.
1344.
1345.
[SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)]
1346.
protected
override
void
WndProc(
ref
Message m) {
1347.
switch
(m.Msg) {
1348.
case
NativeMethods.WM_LBUTTONDOWN:
1349.
FocusInternal();
1350.
if
(!ValidationCancelled) {
1351.
base
.WndProc(
ref
m);
1352.
}
1353.
break
;
1354.
case
NativeMethods.WM_REFLECT + NativeMethods.WM_NOTIFY:
1355.
WmReflectCommand(
ref
m);
1356.
base
.WndProc(
ref
m);
1357.
break
;
1358.
case
NativeMethods.WM_WINDOWPOSCHANGED:
1359.
base
.WndProc(
ref
m);
1360.
UpdateUpDown();
1361.
break
;
1362.
default
:
1363.
base
.WndProc(
ref
m);
1364.
break
;
1365.
}
1366.
}
1367.
1368.
1369.
internal
static
NativeMethods.SYSTEMTIME DateTimeToSysTime(DateTime time) {
1370.
NativeMethods.SYSTEMTIME sys =
new
NativeMethods.SYSTEMTIME();
1371.
sys.wYear = (
short
)time.Year;
1372.
sys.wMonth = (
short
)time.Month;
1373.
sys.wDayOfWeek = (
short
)time.DayOfWeek;
1374.
sys.wDay = (
short
)time.Day;
1375.
sys.wHour = (
short
)time.Hour;
1376.
sys.wMinute = (
short
)time.Minute;
1377.
sys.wSecond = (
short
)time.Second;
1378.
sys.wMilliseconds = 0;
1379.
return
sys;
1380.
}
1381.
1382.
1383.
internal
static
DateTime SysTimeToDateTime(NativeMethods.SYSTEMTIME s) {
1384.
return
new
DateTime(s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wSecond);
1385.
}
1386.
1387.
/// <devdoc>
1388.
/// </devdoc>
1389.
private
sealed
class
EnumChildren {
1390.
public
IntPtr hwndFound = IntPtr.Zero;
1391.
1392.
public
bool
enumChildren(IntPtr hwnd, IntPtr lparam) {
1393.
hwndFound = hwnd;
1394.
return
true
;
1395.
}
1396.
}
1397.
1398.
1399.
[ComVisible(
true
)]
1400.
public
class
DateTimePickerAccessibleObject : ControlAccessibleObject {
1401.
1402.
1403.
public
DateTimePickerAccessibleObject(DateTimePicker owner) :
base
(owner) {
1404.
}
1405.
1406.
1407.
public
override
string
KeyboardShortcut {
1408.
get
{
1409.
1410.
Label previousLabel =
this
.PreviousLabel;
1411.
1412.
if
(previousLabel !=
null
) {
1413.
char
previousLabelMnemonic = WindowsFormsUtils.GetMnemonic(previousLabel.Text,
false
);
1414.
if
(previousLabelMnemonic != (
char
) 0) {
1415.
return
"Alt+"
+ previousLabelMnemonic;
1416.
}
1417.
}
1418.
1419.
string
baseShortcut =
base
.KeyboardShortcut;
1420.
1421.
if
((baseShortcut ==
null
|| baseShortcut.Length == 0)) {
1422.
char
ownerTextMnemonic = WindowsFormsUtils.GetMnemonic(
this
.Owner.Text,
false
);
1423.
if
(ownerTextMnemonic != (
char
) 0) {
1424.
return
"Alt+"
+ ownerTextMnemonic;
1425.
}
1426.
}
1427.
1428.
return
baseShortcut;
1429.
}
1430.
}
1431.
1432.
1433.
public
override
string
Value {
1434.
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
1435.
get
{
1436.
string
baseValue =
base
.Value;
1437.
if
(baseValue ==
null
|| baseValue.Length == 0) {
1438.
return
Owner.Text;
1439.
}
1440.
return
baseValue;
1441.
}
1442.
}
1443.
1444.
1445.
public
override
AccessibleStates State {
1446.
get
{
1447.
AccessibleStates state =
base
.State;
1448.
1449.
if
(((DateTimePicker)Owner).ShowCheckBox &&
1450.
((DateTimePicker)Owner).Checked) {
1451.
state |= AccessibleStates.Checked;
1452.
}
1453.
1454.
return
state;
1455.
}
1456.
}
1457.
1458.
1459.
public
override
AccessibleRole Role {
1460.
get
{
1461.
AccessibleRole role = Owner.AccessibleRole;
1462.
if
(role != AccessibleRole.Default) {
1463.
return
role;
1464.
}
1465.
return
AccessibleRole.DropList;
1466.
}
1467.
}
1468.
1469.
}
1470.
}