Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / EventHandlerService.cs / 1 / EventHandlerService.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms.Design { using System.Diagnostics; using System; using System.Windows.Forms; ////// /// /// public sealed class EventHandlerService : IEventHandlerService { // We cache the last requested handler for speed. // private object lastHandler; private Type lastHandlerType; // The handler stack // private HandlerEntry handlerHead; // Our change event // private EventHandler changedEvent; private readonly Control focusWnd; ////// /// public EventHandlerService(Control focusWnd) { this.focusWnd = focusWnd; } ///[To be supplied.] ////// /// public event EventHandler EventHandlerChanged { add { changedEvent += value; } remove { changedEvent -= value; } } ///[To be supplied.] ////// /// public Control FocusWindow { get { return focusWnd; } } ///[To be supplied.] ////// /// public object GetHandler(Type handlerType) { if (handlerType == lastHandlerType) { return lastHandler; } for (HandlerEntry entry = handlerHead; entry != null; entry = entry.next) { if (entry.handler != null && handlerType.IsInstanceOfType(entry.handler)) { lastHandlerType = handlerType; lastHandler = entry.handler; return entry.handler; } } return null; } ////// Gets the currently active event handler of the specified type. ////// /// Fires an OnEventHandlerChanged event. /// private void OnEventHandlerChanged(EventArgs e) { if (changedEvent != null) { ((EventHandler)changedEvent)(this, e); } } ////// /// public void PopHandler(object handler) { for (HandlerEntry entry = handlerHead; entry != null; entry = entry.next) { if (entry.handler == handler) { handlerHead = entry.next; lastHandler = null; lastHandlerType = null; OnEventHandlerChanged(EventArgs.Empty); return; } } Debug.Assert(handler == null || handlerHead == null, "Failed to locate handler to remove from list."); } ////// Pops /// the given handler off of the stack. ////// /// public void PushHandler(object handler) { handlerHead = new HandlerEntry(handler, handlerHead); // Update the handlerType if the Handler pushed is the same type as the last one .... // This is true when SplitContainer is on the form and Edit Properties pushed another handler. lastHandlerType = handler.GetType(); lastHandler = handlerHead.handler; OnEventHandlerChanged(EventArgs.Empty); } ///Pushes a new event handler on the stack. ////// /// Contains a single node of our handler stack. We typically /// have very few handlers, and the handlers are long-living, so /// I just implemented this as a linked list. /// private sealed class HandlerEntry { public object handler; public HandlerEntry next; ////// /// Creates a new handler entry objet. /// public HandlerEntry(object handler, HandlerEntry next) { this.handler = handler; this.next = next; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLConvert.cs
- srgsitem.cs
- GenericAuthenticationEventArgs.cs
- WebServiceHandler.cs
- ValueSerializer.cs
- SqlProfileProvider.cs
- DbConnectionPoolOptions.cs
- TextCharacters.cs
- PageTheme.cs
- ScaleTransform.cs
- SignalGate.cs
- EmptyEnumerable.cs
- SubclassTypeValidatorAttribute.cs
- SqlDataSourceFilteringEventArgs.cs
- MessageHeader.cs
- XamlSerializerUtil.cs
- SchemaImporterExtensionsSection.cs
- AssertSection.cs
- WebExceptionStatus.cs
- WindowsFormsSectionHandler.cs
- SchemaImporterExtension.cs
- Trace.cs
- PartialCachingControl.cs
- MatrixKeyFrameCollection.cs
- X509IssuerSerialKeyIdentifierClause.cs
- KeyValueConfigurationCollection.cs
- BooleanAnimationUsingKeyFrames.cs
- NavigateEvent.cs
- ManualResetEvent.cs
- CustomAttributeFormatException.cs
- DataGridItemCollection.cs
- TextRunCacheImp.cs
- SamlAuthorityBinding.cs
- TemplateBindingExpression.cs
- SQLBytes.cs
- ResourceBinder.cs
- PointAnimation.cs
- StrokeCollection2.cs
- indexingfiltermarshaler.cs
- CategoryNameCollection.cs
- ToolStripActionList.cs
- FontInfo.cs
- PermissionSetEnumerator.cs
- Tokenizer.cs
- Pkcs7Signer.cs
- __Filters.cs
- JsonDeserializer.cs
- HorizontalAlignConverter.cs
- Constant.cs
- Timer.cs
- MemoryPressure.cs
- OleDbMetaDataFactory.cs
- PassportIdentity.cs
- CellIdBoolean.cs
- PersonalizationProvider.cs
- WindowsPrincipal.cs
- input.cs
- RegisteredDisposeScript.cs
- X500Name.cs
- TypeInitializationException.cs
- RemotingException.cs
- MenuItemStyleCollection.cs
- SerialReceived.cs
- AttributeQuery.cs
- ServiceContractGenerationContext.cs
- SafeCryptoHandles.cs
- TextTabProperties.cs
- Collection.cs
- Point4DConverter.cs
- ProgressPage.cs
- BlurBitmapEffect.cs
- RegexCaptureCollection.cs
- StoragePropertyMapping.cs
- FixedBufferAttribute.cs
- ReferencedAssembly.cs
- AxisAngleRotation3D.cs
- QuaternionRotation3D.cs
- SystemColors.cs
- ToolStripProgressBar.cs
- AttributeQuery.cs
- SHA384Managed.cs
- XmlException.cs
- DataTable.cs
- ParameterElement.cs
- WebPartMenu.cs
- ColorBlend.cs
- ExtensionWindowHeader.cs
- PrtCap_Base.cs
- ImmComposition.cs
- AxDesigner.cs
- SqlDataSourceWizardForm.cs
- MemberInitExpression.cs
- ApplicationActivator.cs
- PathNode.cs
- OrthographicCamera.cs
- DbParameterCollection.cs
- CertificateManager.cs
- TypeBuilderInstantiation.cs
- ClassDataContract.cs
- KerberosRequestorSecurityToken.cs