Code:
/ FX-1434 / FX-1434 / 1.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; ////// /// /// public class DateTimeEditor : UITypeEditor { ////// This date/time editor is a UITypeEditor suitable for /// visually editing DateTime objects. /// ////// /// 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
- initElementDictionary.cs
- WebPartHelpVerb.cs
- NamedPipeTransportSecurityElement.cs
- CacheDependency.cs
- LinqDataSourceContextEventArgs.cs
- ControlBuilder.cs
- CancellationState.cs
- IntegrationExceptionEventArgs.cs
- ViewLoader.cs
- WebPartChrome.cs
- ByteStack.cs
- CompModHelpers.cs
- MenuEventArgs.cs
- _ConnectOverlappedAsyncResult.cs
- CheckPair.cs
- HotCommands.cs
- TemplateKeyConverter.cs
- XamlSerializer.cs
- CustomWebEventKey.cs
- HostingEnvironmentException.cs
- ListBindingConverter.cs
- EncoderBestFitFallback.cs
- IIS7UserPrincipal.cs
- ResourceReferenceKeyNotFoundException.cs
- ObjectPropertyMapping.cs
- FixedSOMElement.cs
- DocumentPageTextView.cs
- PrePostDescendentsWalker.cs
- Splitter.cs
- sqlcontext.cs
- OdbcRowUpdatingEvent.cs
- Binding.cs
- FileFormatException.cs
- Metadata.cs
- MimeTypeAttribute.cs
- SQLSingleStorage.cs
- NamespaceListProperty.cs
- BufferCache.cs
- DirectionalLight.cs
- Connector.cs
- CopyNamespacesAction.cs
- XmlDocumentViewSchema.cs
- DrawListViewItemEventArgs.cs
- TextTreeFixupNode.cs
- HttpBrowserCapabilitiesBase.cs
- GuidConverter.cs
- RoleManagerModule.cs
- EmptyStringExpandableObjectConverter.cs
- XmlIncludeAttribute.cs
- Int64AnimationUsingKeyFrames.cs
- ScopeCollection.cs
- COM2IDispatchConverter.cs
- WebPartConnectionsCloseVerb.cs
- WebPartUserCapability.cs
- CatalogZone.cs
- HelpFileFileNameEditor.cs
- DiagnosticsConfigurationHandler.cs
- WeakEventManager.cs
- TextSerializer.cs
- TextEditorParagraphs.cs
- ScriptBehaviorDescriptor.cs
- MatchingStyle.cs
- ConsumerConnectionPoint.cs
- figurelength.cs
- SecurityKeyType.cs
- CompensatableTransactionScopeActivity.cs
- Decoder.cs
- EventMappingSettingsCollection.cs
- RawStylusInputCustomDataList.cs
- GetPageCompletedEventArgs.cs
- EventBuilder.cs
- DSASignatureDeformatter.cs
- XmlArrayItemAttributes.cs
- FileDialogCustomPlace.cs
- HoistedLocals.cs
- ChannelServices.cs
- XmlLangPropertyAttribute.cs
- DependentList.cs
- StateValidator.cs
- ProgressBar.cs
- QuaternionValueSerializer.cs
- QueryMath.cs
- UIElementPropertyUndoUnit.cs
- LoginName.cs
- BamlRecordWriter.cs
- EntityModelSchemaGenerator.cs
- MenuItem.cs
- Panel.cs
- Assert.cs
- UnionCodeGroup.cs
- Vector3DKeyFrameCollection.cs
- SoapObjectInfo.cs
- TripleDESCryptoServiceProvider.cs
- SynchronizedInputHelper.cs
- HitTestFilterBehavior.cs
- TableItemStyle.cs
- PackageRelationshipSelector.cs
- QueryExpr.cs
- PropertyPushdownHelper.cs
- MetadataProperty.cs