Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / ToolStripContainerActionList.cs / 2 / ToolStripContainerActionList.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.Design { using System; using System.Design; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Windows.Forms; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Windows.Forms.Design.Behavior; ////// Describes the list of actions that can be performed for the ToolStripContainer control from the /// chrome pannel. /// internal class ToolStripContainerActionList : DesignerActionList { ToolStripContainer container; IServiceProvider provider = null; IDesignerHost host = null; ////// ToolStripcontainer ActionList. /// public ToolStripContainerActionList(ToolStripContainer control) : base(control) { this.container = control; provider = container.Site; host = provider.GetService (typeof(IDesignerHost)) as IDesignerHost; } //helper function to get the property on the comp [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] private object GetProperty(Component comp, string propertyName) { PropertyDescriptor getProperty = TypeDescriptor.GetProperties(comp)[propertyName]; Debug.Assert( getProperty != null, "Could not find given property in control."); if( getProperty != null ) { return getProperty.GetValue(comp); } return null; } //helper function to change the property on the comp [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] private void ChangeProperty(Component comp, string propertyName, object value) { if (host != null) { ToolStripPanel panel = comp as ToolStripPanel; ToolStripPanelDesigner panelDesigner = host.GetDesigner(comp) as ToolStripPanelDesigner; if (propertyName.Equals("Visible")) { foreach(Control c in panel.Controls) { PropertyDescriptor visibleProperty = TypeDescriptor.GetProperties(c)["Visible"]; Debug.Assert(visibleProperty != null, "Could not find given property in control." ); if(visibleProperty != null ) { visibleProperty.SetValue(c, value); } } if (!((bool)value)) { if (panel != null) { panel.Padding = new Padding(0); } if (panelDesigner != null) { if(panelDesigner.ToolStripPanelSelectorGlyph != null) { panelDesigner.ToolStripPanelSelectorGlyph.IsExpanded = false; } } } } PropertyDescriptor changingProperty = TypeDescriptor.GetProperties(comp)[propertyName]; Debug.Assert( changingProperty != null, "Could not find given property in control." ); if( changingProperty != null ) { changingProperty.SetValue(comp, value); } //Reset the Glyphs. SelectionManager selMgr = (SelectionManager)provider.GetService(typeof(SelectionManager)); if (selMgr != null) { selMgr.Refresh(); } // Invlidate the Window... if (panelDesigner != null) { panelDesigner.InvalidateGlyph(); } } } ////// Checks if the ToolStrip Container is DOCK FILLED /// private bool IsDockFilled { get { PropertyDescriptor dockProp = TypeDescriptor.GetProperties(container)["Dock"]; if (dockProp != null && ((DockStyle)dockProp.GetValue(container)) != DockStyle.Fill) { return false; } return true; } } ////// Checks if the ToolStripContainer is a child control of the designerHost's rootComponent /// private bool ProvideReparent { get { if (host != null) { Control root = host.RootComponent as Control; // Reparent the Controls only if the ToolStripContainer is a child of the RootComponent... if (root != null && container.Parent == root && IsDockFilled && root.Controls.Count > 1) { return true; } } return false; } } ////// Sets the Dock.. /// [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] public void SetDockToForm() { if (host != null) { Control root = host.RootComponent as Control; //change the Parent only if its not parented to the form. if (root != null && container.Parent != root) { root.Controls.Add(container); } //set the dock prop to DockStyle.Fill if (!IsDockFilled) { PropertyDescriptor dockProp = TypeDescriptor.GetProperties(container)["Dock"]; if (dockProp != null) { dockProp.SetValue(container, DockStyle.Fill); } } } } ////// Reparent the controls on the form. /// [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] public void ReparentControls() { if (host != null) { Control root = host.RootComponent as Control; // Reparent the Controls only if the ToolStripContainer is a child of the RootComponent... if (root != null && container.Parent == root && root.Controls.Count > 1) { Control newParent = container.ContentPanel; PropertyDescriptor autoScrollProp = TypeDescriptor.GetProperties(newParent)["AutoScroll"]; if (autoScrollProp != null) { autoScrollProp.SetValue(newParent, true); } // create a transaction so this happens as an atomic unit. DesignerTransaction changeParent = host.CreateTransaction("Reparent Transaction"); try { Control[] childControls = new Control[root.Controls.Count]; root.Controls.CopyTo(childControls, 0); foreach(Control c in childControls) { if (c == container || c is MdiClient) { continue; } // We should not reparent inherited Controls... InheritanceAttribute ia = (InheritanceAttribute)TypeDescriptor.GetAttributes(c)[typeof(InheritanceAttribute)]; if (ia == null || ia.InheritanceLevel == InheritanceLevel.InheritedReadOnly) { continue; } IComponentChangeService changeSvc = provider.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (c is ToolStrip) { newParent = GetParent(c); } else { newParent = container.ContentPanel; } PropertyDescriptor controlsProp = TypeDescriptor.GetProperties(newParent)["Controls"]; Control oldParent = c.Parent; if (oldParent != null) { if (changeSvc != null) { changeSvc.OnComponentChanging(oldParent, controlsProp); } //remove control from the old parent oldParent.Controls.Remove(c); } if (changeSvc != null) { changeSvc.OnComponentChanging(newParent, controlsProp); } //finally add & relocate the control with the new parent newParent.Controls.Add(c); //fire our comp changed events if (changeSvc != null && oldParent != null) { changeSvc.OnComponentChanged(oldParent, controlsProp, null, null); } // fire comp changed on the newParent if (changeSvc != null) { changeSvc.OnComponentChanged(newParent, controlsProp, null, null); } } } catch { if (changeParent != null) { changeParent.Cancel(); changeParent = null; } } finally { if (changeParent != null) { changeParent.Commit(); changeParent = null; } //Set the Selection on the new Parent ... so that the selection is restored to the new item, ISelectionService selSvc = provider.GetService(typeof(ISelectionService)) as ISelectionService; if (selSvc != null) { selSvc.SetSelectedComponents(new IComponent[] { newParent }); } } } } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] private Control GetParent(Control c) { Control newParent = container.ContentPanel; DockStyle dock = c.Dock; foreach(Control panel in container.Controls) { if (panel is ToolStripPanel) { if (panel.Dock == dock) { newParent = panel; break; } } } return newParent; } ////// Visibility of TopToolStripPanel. /// public bool TopVisible { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return (bool)GetProperty(container, "TopToolStripPanelVisible"); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { if (value != TopVisible) { ChangeProperty(container, "TopToolStripPanelVisible", (object)value); } } } ////// Visibility of BottomToolStripPanel. /// public bool BottomVisible { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return (bool)GetProperty(container, "BottomToolStripPanelVisible"); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { if (value != BottomVisible) { ChangeProperty(container, "BottomToolStripPanelVisible", (object)value); } } } ////// Visibility of LeftToolStripPanel. /// public bool LeftVisible { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return (bool)GetProperty(container, "LeftToolStripPanelVisible"); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { if (value != LeftVisible) { ChangeProperty(container, "LeftToolStripPanelVisible", (object)value); } } } ////// Visibility of RightToolStripPanel. /// public bool RightVisible { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] get { return (bool)GetProperty(container, "RightToolStripPanelVisible"); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] set { if (value != RightVisible) { ChangeProperty(container, "RightToolStripPanelVisible", (object)value); } } } ////// Returns the control's action list items. /// public override DesignerActionItemCollection GetSortedActionItems() { DesignerActionItemCollection items = new DesignerActionItemCollection(); items.Add(new DesignerActionHeaderItem(SR.GetString(SR.ToolStripContainerActionList_Visible), SR.GetString(SR.ToolStripContainerActionList_Show))); items.Add(new DesignerActionPropertyItem("TopVisible", SR.GetString(SR.ToolStripContainerActionList_Top), SR.GetString(SR.ToolStripContainerActionList_Show), SR.GetString(SR.ToolStripContainerActionList_TopDesc))); items.Add(new DesignerActionPropertyItem("BottomVisible", SR.GetString(SR.ToolStripContainerActionList_Bottom), SR.GetString(SR.ToolStripContainerActionList_Show), SR.GetString(SR.ToolStripContainerActionList_BottomDesc))); items.Add(new DesignerActionPropertyItem("LeftVisible", SR.GetString(SR.ToolStripContainerActionList_Left), SR.GetString(SR.ToolStripContainerActionList_Show), SR.GetString(SR.ToolStripContainerActionList_LeftDesc))); items.Add(new DesignerActionPropertyItem("RightVisible", SR.GetString(SR.ToolStripContainerActionList_Right), SR.GetString(SR.ToolStripContainerActionList_Show), SR.GetString(SR.ToolStripContainerActionList_RightDesc))); if (!IsDockFilled) { bool parentIsForm = true; if (host != null) { Control userControl = host.RootComponent as UserControl; if (userControl != null) { parentIsForm = false; } } items.Add(new DesignerActionMethodItem(this, "SetDockToForm", parentIsForm ? SR.GetString(SR.DesignerShortcutDockInForm) : SR.GetString(SR.DesignerShortcutDockInUserControl))); } if (ProvideReparent) { items.Add(new DesignerActionMethodItem(this, "ReparentControls", SR.GetString(SR.DesignerShortcutReparentControls))); } return items; } } } // 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
- ClosableStream.cs
- SecureUICommand.cs
- ObjectAssociationEndMapping.cs
- TemplateBindingExtensionConverter.cs
- SettingsProperty.cs
- GroupDescription.cs
- WebResponse.cs
- FeatureManager.cs
- BinaryObjectInfo.cs
- XmlValidatingReaderImpl.cs
- QueuePathEditor.cs
- BamlRecords.cs
- CodeCommentStatementCollection.cs
- XmlSchemaInfo.cs
- ApplicationContext.cs
- HwndSourceKeyboardInputSite.cs
- ReceiveContext.cs
- SkewTransform.cs
- NativeMethods.cs
- TrackingCondition.cs
- LineBreakRecord.cs
- ReturnValue.cs
- ProjectionAnalyzer.cs
- GetWinFXPath.cs
- Rect3DValueSerializer.cs
- BulletedList.cs
- ExtenderControl.cs
- FactoryGenerator.cs
- Baml2006KnownTypes.cs
- SchemaInfo.cs
- Drawing.cs
- BamlRecords.cs
- DefaultPropertyAttribute.cs
- FlowDocumentScrollViewer.cs
- GlyphElement.cs
- ISAPIWorkerRequest.cs
- Attribute.cs
- Hex.cs
- CodeAttributeDeclarationCollection.cs
- _LazyAsyncResult.cs
- VolatileEnlistmentState.cs
- SplineKeyFrames.cs
- EncoderReplacementFallback.cs
- StrongNamePublicKeyBlob.cs
- BitmapEffectCollection.cs
- TreeNodeSelectionProcessor.cs
- EncoderParameter.cs
- WizardPanelChangingEventArgs.cs
- _AuthenticationState.cs
- InboundActivityHelper.cs
- WindowsBrush.cs
- ServiceParser.cs
- XmlCountingReader.cs
- PhonemeEventArgs.cs
- GridViewHeaderRowPresenter.cs
- DocumentGridContextMenu.cs
- Polyline.cs
- SystemColors.cs
- NetNamedPipeSecurityElement.cs
- SchemaTypeEmitter.cs
- ParseChildrenAsPropertiesAttribute.cs
- PropertyStore.cs
- BitmapEffectGeneralTransform.cs
- FormView.cs
- SystemColorTracker.cs
- BulletDecorator.cs
- LoaderAllocator.cs
- configsystem.cs
- HtmlTableRow.cs
- RealProxy.cs
- PasswordRecoveryDesigner.cs
- ElementAtQueryOperator.cs
- SqlDependency.cs
- JsonEncodingStreamWrapper.cs
- LayoutEditorPart.cs
- ErrorFormatter.cs
- MessageHeaderAttribute.cs
- Rotation3DKeyFrameCollection.cs
- DataGridToolTip.cs
- PermissionSetTriple.cs
- DataServiceException.cs
- FileDetails.cs
- ProcessModelSection.cs
- ISAPIApplicationHost.cs
- MessagePartProtectionMode.cs
- ListViewItemSelectionChangedEvent.cs
- MethodToken.cs
- AlphabetConverter.cs
- ArrangedElementCollection.cs
- SourceLineInfo.cs
- MultiSelectRootGridEntry.cs
- MenuBase.cs
- SplayTreeNode.cs
- FastEncoder.cs
- SourceElementsCollection.cs
- LicenseProviderAttribute.cs
- VisualBrush.cs
- SqlTypeSystemProvider.cs
- GrammarBuilderDictation.cs
- RootDesignerSerializerAttribute.cs