Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / CompMod / System / ComponentModel / Design / DateTimeEditor.cs / 1 / DateTimeEditor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.ComponentModel.Design {
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Win32;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
///
///
///
///
/// This date/time editor is a UITypeEditor suitable for
/// visually editing DateTime objects.
///
///
public class DateTimeEditor : UITypeEditor {
///
///
/// Edits the given object value using the editor style provided by
/// GetEditorStyle. A service provider is provided so that any
/// required editing services can be obtained.
///
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust.
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
object returnValue = value;
if (provider != null) {
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null) {
using (DateTimeUI dateTimeUI = new DateTimeUI()) {
dateTimeUI.Start(edSvc, value);
edSvc.DropDownControl(dateTimeUI);
value = dateTimeUI.Value;
dateTimeUI.End();
}
}
}
return value;
}
///
///
/// Retrieves the editing style of the Edit method. If the method
/// is not supported, this will return None.
///
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust.
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
return UITypeEditorEditStyle.DropDown;
}
///
///
/// UI we drop down to pick dates.
///
private class DateTimeUI : Control {
private MonthCalendar monthCalendar = new DateTimeMonthCalendar();
private object value;
private IWindowsFormsEditorService edSvc;
///
///
///
public DateTimeUI() {
InitializeComponent();
Size = monthCalendar.SingleMonthSize;
monthCalendar.Resize += new EventHandler(this.MonthCalResize);
}
///
///
///
public object Value {
get {
return value;
}
}
///
///
///
public void End() {
edSvc = null;
value = null;
}
private void MonthCalKeyDown(object sender, KeyEventArgs e) {
switch (e.KeyCode) {
case Keys.Enter:
OnDateSelected(sender, null);
break;
}
}
///
///
///
private void InitializeComponent() {
monthCalendar.DateSelected += new DateRangeEventHandler(this.OnDateSelected);
monthCalendar.KeyDown += new KeyEventHandler(this.MonthCalKeyDown);
this.Controls.Add(monthCalendar);
}
private void MonthCalResize(object sender, EventArgs e) {
this.Size = monthCalendar.Size;
}
///
///
///
private void OnDateSelected(object sender, DateRangeEventArgs e) {
value = monthCalendar.SelectionStart;
edSvc.CloseDropDown();
}
protected override void OnGotFocus(EventArgs e) {
base.OnGotFocus(e);
monthCalendar.Focus();
}
///
///
///
public void Start(IWindowsFormsEditorService edSvc, object value) {
this.edSvc = edSvc;
this.value = value;
if (value != null) {
DateTime dt = (DateTime) value;
monthCalendar.SetDate((dt.Equals(DateTime.MinValue)) ? DateTime.Today : dt);
}
}
class DateTimeMonthCalendar : MonthCalendar {
protected override bool IsInputKey(System.Windows.Forms.Keys keyData) {
switch (keyData) {
case Keys.Enter:
return true;
}
return base.IsInputKey(keyData);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FixedSOMTextRun.cs
- OdbcPermission.cs
- ExclusiveHandle.cs
- SoapHeader.cs
- Scanner.cs
- TypedReference.cs
- LinearKeyFrames.cs
- SiblingIterators.cs
- ProfilePropertyNameValidator.cs
- RequestQueryParser.cs
- AuthorizationPolicyTypeElement.cs
- SessionIDManager.cs
- ParentControlDesigner.cs
- ClientCultureInfo.cs
- GestureRecognizer.cs
- RootProjectionNode.cs
- NetworkInterface.cs
- HelpKeywordAttribute.cs
- Item.cs
- AsynchronousChannel.cs
- SystemIPAddressInformation.cs
- ObjectQueryState.cs
- ConfigXmlDocument.cs
- Pens.cs
- ObjRef.cs
- VariableDesigner.xaml.cs
- Stream.cs
- FixedSOMPageConstructor.cs
- BrowserInteropHelper.cs
- CodeIterationStatement.cs
- MenuAutomationPeer.cs
- NodeInfo.cs
- DataServiceBehavior.cs
- Crc32.cs
- SqlBulkCopy.cs
- Graph.cs
- SecurityContextTokenValidationException.cs
- CallId.cs
- TypeInfo.cs
- XmlUtil.cs
- CurrentChangedEventManager.cs
- ColorKeyFrameCollection.cs
- ObjectDataSourceFilteringEventArgs.cs
- ScriptControl.cs
- SpotLight.cs
- StylusPointDescription.cs
- DrawingVisualDrawingContext.cs
- WSHttpBindingBase.cs
- VsPropertyGrid.cs
- PropertyNames.cs
- ColumnResizeUndoUnit.cs
- CatalogPart.cs
- IconHelper.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- StreamingContext.cs
- CodeSubDirectory.cs
- VisualBrush.cs
- StorageTypeMapping.cs
- HitTestResult.cs
- FixedSOMGroup.cs
- MetadataUtil.cs
- ByteRangeDownloader.cs
- RoleService.cs
- XmlHierarchicalEnumerable.cs
- ManagedFilter.cs
- ProgressBarBrushConverter.cs
- WindowsListViewItemCheckBox.cs
- RtfToXamlLexer.cs
- MessagingDescriptionAttribute.cs
- RegexTree.cs
- LocalizableAttribute.cs
- ErrorProvider.cs
- DataGridViewCellFormattingEventArgs.cs
- TextElementEditingBehaviorAttribute.cs
- ApplicationManager.cs
- InvalidComObjectException.cs
- UTF32Encoding.cs
- SqlConnectionPoolProviderInfo.cs
- WebPartRestoreVerb.cs
- ReadonlyMessageFilter.cs
- NavigationWindow.cs
- HostingEnvironment.cs
- Graphics.cs
- CodeConstructor.cs
- SecurityListenerSettingsLifetimeManager.cs
- ToolBar.cs
- DataGridViewImageColumn.cs
- RemotingServices.cs
- AutomationIdentifier.cs
- PagesChangedEventArgs.cs
- LayoutTableCell.cs
- ZipIOLocalFileBlock.cs
- SafeHandle.cs
- BlurBitmapEffect.cs
- ClaimComparer.cs
- PathNode.cs
- EntityDataSourceWizardForm.cs
- QuaternionAnimation.cs
- SmiRequestExecutor.cs
- PersonalizationState.cs