Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / DesignerExtenders.cs / 1 / DesignerExtenders.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms.Design { using System; using System.CodeDom; using System.CodeDom.Compiler; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Design; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Diagnostics.CodeAnalysis; ////// This class provides the Modifiers property to components. It is shared between /// the document designer and the component document designer. /// internal class DesignerExtenders { private IExtenderProvider[] providers; private IExtenderProviderService extenderService; ////// /// This is called by a root designer to add the correct extender providers. /// public DesignerExtenders(IExtenderProviderService ex) { this.extenderService = ex; if (providers == null) { providers = new IExtenderProvider[] { new NameExtenderProvider(), new NameInheritedExtenderProvider() }; } for (int i = 0; i < providers.Length; i++) { ex.AddExtenderProvider(providers[i]); } } ////// /// This is called at the appropriate time to remove any extra extender /// providers previously added to the designer host. /// public void Dispose() { if (extenderService != null && providers != null) { for (int i = 0; i < providers.Length; i++) { extenderService.RemoveExtenderProvider(providers[i]); } providers = null; extenderService = null; } } ////// This is the base extender provider for all winform document /// designers. It provides the "Name" property. /// [ ProvideProperty("Name", typeof(IComponent)) ] private class NameExtenderProvider : IExtenderProvider { private IComponent baseComponent; ////// Creates a new DocumentExtenderProvider. /// internal NameExtenderProvider() { } protected IComponent GetBaseComponent(object o) { if (baseComponent == null) { ISite site = ((IComponent)o).Site; if (site != null) { IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost)); if (host != null) { baseComponent = host.RootComponent; } } } return baseComponent; } ////// Determines if ths extender provider can extend the given object. We extend /// all objects, so we always return true. /// public virtual bool CanExtend(object o) { // We always extend the root // IComponent baseComp = GetBaseComponent(o); if (baseComp == o) { return true; } // See if this object is inherited. If so, then we don't want to // extend. // if (!TypeDescriptor.GetAttributes(o)[typeof(InheritanceAttribute)].Equals(InheritanceAttribute.NotInherited)) { return false; } return true; } ////// This is an extender property that we offer to all components /// on the form. It implements the "Name" property. /// [ DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ParenthesizePropertyName(true), MergableProperty(false), SRDescriptionAttribute(SR.DesignerPropName), Category("Design") ] [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] public virtual string GetName(IComponent comp) { ISite site = comp.Site; if (site != null) { return site.Name; } return null; } ////// This is an extender property that we offer to all components /// on the form. It implements the "Name" property. /// [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] public void SetName(IComponent comp, string newName) { ISite site = comp.Site; if (site != null) { site.Name = newName; } } } ////// This extender provider offers up read-only versions of "Name" property /// for inherited components. /// private class NameInheritedExtenderProvider : NameExtenderProvider { ////// Creates a new DocumentInheritedExtenderProvider. /// internal NameInheritedExtenderProvider() { } ////// Determines if ths extender provider can extend the given object. We extend /// all objects, so we always return true. /// public override bool CanExtend(object o) { // We never extend the root // IComponent baseComp = GetBaseComponent(o); if (baseComp == o) { return false; } // See if this object is inherited. If so, then we are interested in it. // if (!TypeDescriptor.GetAttributes(o)[typeof(InheritanceAttribute)].Equals(InheritanceAttribute.NotInherited)) { return true; } return false; } [ReadOnly(true)] public override string GetName(IComponent comp) { return base.GetName(comp); } } } } // 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
- KeyPressEvent.cs
- GraphicsContext.cs
- NumericUpDownAcceleration.cs
- OdbcDataReader.cs
- StylusShape.cs
- LinqDataSourceDeleteEventArgs.cs
- BufferModesCollection.cs
- GPRECTF.cs
- Crc32.cs
- SemanticTag.cs
- NamedPipeProcessProtocolHandler.cs
- ResXDataNode.cs
- TimeSpan.cs
- XmlSchemaSimpleType.cs
- CompensatableTransactionScopeActivity.cs
- PrinterResolution.cs
- EntityDataSourceWrapper.cs
- PackageController.cs
- RulePatternOps.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- TextTreeExtractElementUndoUnit.cs
- TrustVersion.cs
- dsa.cs
- TypeRefElement.cs
- FormsAuthenticationUserCollection.cs
- AnnotationComponentChooser.cs
- EntityTransaction.cs
- SchemaImporterExtension.cs
- DesignerForm.cs
- XmlCustomFormatter.cs
- RichTextBox.cs
- ActivityBuilderXamlWriter.cs
- ObjectDataSourceFilteringEventArgs.cs
- WmlCalendarAdapter.cs
- ScriptReference.cs
- TimeSpanStorage.cs
- ManagementEventWatcher.cs
- NonVisualControlAttribute.cs
- SqlConnectionHelper.cs
- WindowsListViewScroll.cs
- WSSecureConversationDec2005.cs
- WindowShowOrOpenTracker.cs
- SByteConverter.cs
- CompilerError.cs
- InputLangChangeEvent.cs
- LoadedEvent.cs
- ProviderUtil.cs
- SimpleHandlerFactory.cs
- ListView.cs
- SystemBrushes.cs
- XXXOnTypeBuilderInstantiation.cs
- PropVariant.cs
- BasicExpressionVisitor.cs
- FindSimilarActivitiesVerb.cs
- AsmxEndpointPickerExtension.cs
- NTAccount.cs
- GetCardDetailsRequest.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- Switch.cs
- XDRSchema.cs
- PipeConnection.cs
- ExpressionBindingCollection.cs
- DataGridViewBindingCompleteEventArgs.cs
- SecurityHeader.cs
- FixedTextPointer.cs
- AuthorizationPolicyTypeElementCollection.cs
- StopStoryboard.cs
- DataListItemCollection.cs
- AtomParser.cs
- updatecommandorderer.cs
- TdsParserSessionPool.cs
- SchemaNotation.cs
- SqlMethodCallConverter.cs
- TimeSpanValidator.cs
- View.cs
- Cloud.cs
- sqlcontext.cs
- XmlSchemaSimpleContentExtension.cs
- HyperlinkAutomationPeer.cs
- MenuScrollingVisibilityConverter.cs
- PeerHopCountAttribute.cs
- AuthorizationSection.cs
- ToolTipAutomationPeer.cs
- StrongNameIdentityPermission.cs
- SafeBitVector32.cs
- GlyphingCache.cs
- DbTransaction.cs
- Point4D.cs
- LinkedResourceCollection.cs
- SrgsSubset.cs
- CodeTypeConstructor.cs
- DataGridViewCellStyle.cs
- Vector.cs
- RawStylusInputCustomDataList.cs
- TreeViewDataItemAutomationPeer.cs
- TemplateKeyConverter.cs
- CodeTypeParameterCollection.cs
- EventHandlingScope.cs
- TrackingServices.cs
- sqlpipe.cs