Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / WinForms / Managed / System / WinForms / ToolStripContainer.cs / 1 / ToolStripContainer.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /// this is the UBER container for ToolStripPanels. namespace System.Windows.Forms { using Microsoft.Win32; using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Collections; using System.Globalization; using System.Windows.Forms.Layout; [ComVisible(true)] [ClassInterface(ClassInterfaceType.AutoDispatch)] [Designer("System.Windows.Forms.Design.ToolStripContainerDesigner, " + AssemblyRef.SystemDesign)] [SRDescription(SR.ToolStripContainerDesc)] public class ToolStripContainer : ContainerControl { private ToolStripPanel topPanel; private ToolStripPanel bottomPanel; private ToolStripPanel leftPanel; private ToolStripPanel rightPanel; private ToolStripContentPanel contentPanel; public ToolStripContainer() { SetStyle(ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); SuspendLayout(); try { // undone - smart demand creation topPanel = new ToolStripPanel(this); bottomPanel = new ToolStripPanel(this); leftPanel = new ToolStripPanel(this); rightPanel = new ToolStripPanel(this); contentPanel = new ToolStripContentPanel(); contentPanel.Dock = DockStyle.Fill; topPanel.Dock = DockStyle.Top; bottomPanel.Dock = DockStyle.Bottom; rightPanel.Dock = DockStyle.Right; leftPanel.Dock = DockStyle.Left; ToolStripContainerTypedControlCollection controlCollection = this.Controls as ToolStripContainerTypedControlCollection; if (controlCollection != null) { controlCollection.AddInternal(contentPanel); controlCollection.AddInternal(leftPanel); controlCollection.AddInternal(rightPanel); controlCollection.AddInternal(topPanel); controlCollection.AddInternal(bottomPanel); } // else consider throw new exception } finally { ResumeLayout(true); } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public override bool AutoScroll { get { return base.AutoScroll; } set { base.AutoScroll = value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new Size AutoScrollMargin { get { return base.AutoScrollMargin; } set { base.AutoScrollMargin = value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new Size AutoScrollMinSize { get { return base.AutoScrollMinSize; } set { base.AutoScrollMinSize = value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new Color BackColor { get { return base.BackColor; } set { base.BackColor = value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new event EventHandler BackColorChanged { add { base.BackColorChanged += value; } remove { base.BackColorChanged -= value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new Image BackgroundImage { get { return base.BackgroundImage; } set { base.BackgroundImage = value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new event EventHandler BackgroundImageChanged { add { base.BackgroundImageChanged += value; } remove { base.BackgroundImageChanged -= value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public override ImageLayout BackgroundImageLayout { get { return base.BackgroundImageLayout; } set { base.BackgroundImageLayout = value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public new event EventHandler BackgroundImageLayoutChanged { add { base.BackgroundImageLayoutChanged += value; } remove { base.BackgroundImageLayoutChanged += value; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerBottomToolStripPanelDescr), Localizable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public ToolStripPanel BottomToolStripPanel { get { return bottomPanel; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerBottomToolStripPanelVisibleDescr), DefaultValue(true) ] public bool BottomToolStripPanelVisible { get { return BottomToolStripPanel.Visible; } set { BottomToolStripPanel.Visible = value; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerContentPanelDescr), Localizable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public ToolStripContentPanel ContentPanel { get { return contentPanel; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public new bool CausesValidation { get { return base.CausesValidation; } set { base.CausesValidation = value; } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler CausesValidationChanged { add { base.CausesValidationChanged += value; } remove { base.CausesValidationChanged -= value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public new ContextMenuStrip ContextMenuStrip { get { return base.ContextMenuStrip; } set { base.ContextMenuStrip = value; } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler ContextMenuStripChanged { add { base.ContextMenuStripChanged += value; } remove { base.ContextMenuStripChanged -= value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public override Cursor Cursor { get { return base.Cursor; } set { base.Cursor = value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public new event EventHandler CursorChanged { add { base.CursorChanged += value; } remove { base.CursorChanged -= value; } } protected override Size DefaultSize { get { return new Size(150, 175); } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public new Color ForeColor { get { return base.ForeColor; } set { base.ForeColor = value; } } [ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public new event EventHandler ForeColorChanged { add { base.ForeColorChanged += value; } remove { base.ForeColorChanged -= value; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerLeftToolStripPanelDescr), Localizable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public ToolStripPanel LeftToolStripPanel { get { return leftPanel; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerLeftToolStripPanelVisibleDescr), DefaultValue(true) ] public bool LeftToolStripPanelVisible { get { return LeftToolStripPanel.Visible; } set { LeftToolStripPanel.Visible = value; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerRightToolStripPanelDescr), Localizable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public ToolStripPanel RightToolStripPanel { get { return rightPanel; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerRightToolStripPanelVisibleDescr), DefaultValue(true) ] public bool RightToolStripPanelVisible { get { return RightToolStripPanel.Visible; } set { RightToolStripPanel.Visible = value; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerTopToolStripPanelDescr), Localizable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public ToolStripPanel TopToolStripPanel { get { return topPanel; } } [ SRCategory(SR.CatAppearance), SRDescription(SR.ToolStripContainerTopToolStripPanelVisibleDescr), DefaultValue(true) ] public bool TopToolStripPanelVisible { get { return TopToolStripPanel.Visible; } set { TopToolStripPanel.Visible = value; } } ////// /// Controls Collection... /// This is overriden so that the Controls.Add ( ) is not Code Gened... /// [EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public new Control.ControlCollection Controls { get { return base.Controls; } } [EditorBrowsable(EditorBrowsableState.Advanced)] protected override Control.ControlCollection CreateControlsInstance() { return new ToolStripContainerTypedControlCollection(this, /*isReadOnly*/true); } protected override void OnRightToLeftChanged(EventArgs e) { base.OnRightToLeftChanged(e); RightToLeft rightToLeft = this.RightToLeft; // no need to suspend layout - we're already in a layout transaction. if (rightToLeft == RightToLeft.Yes) { RightToolStripPanel.Dock = DockStyle.Left; LeftToolStripPanel.Dock = DockStyle.Right; } else { RightToolStripPanel.Dock = DockStyle.Right; LeftToolStripPanel.Dock = DockStyle.Left; } } protected override void OnSizeChanged(EventArgs e) { foreach (Control c in this.Controls) { c.SuspendLayout(); } base.OnSizeChanged(e); foreach (Control c in this.Controls) { c.ResumeLayout(); } } internal override void RecreateHandleCore() { //If ToolStripContainer's Handle is getting created demand create the childControl handle's // Refer vsw : 517556 for more details. if (IsHandleCreated) { foreach(Control c in Controls) { c.CreateControl(true); } } base.RecreateHandleCore(); } internal class ToolStripContainerTypedControlCollection : WindowsFormsUtils.ReadOnlyControlCollection { ToolStripContainer owner; Type contentPanelType = typeof(ToolStripContentPanel); Type panelType = typeof(ToolStripPanel); public ToolStripContainerTypedControlCollection(Control c, bool isReadOnly) : base(c, isReadOnly) { this.owner = c as ToolStripContainer; } public override void Add(Control value) { if (value == null) { throw new ArgumentNullException("value"); } if (IsReadOnly) { throw new NotSupportedException(SR.GetString(SR.ToolStripContainerUseContentPanel)); } Type controlType = value.GetType(); if (!contentPanelType.IsAssignableFrom(controlType) && !panelType.IsAssignableFrom(controlType)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.TypedControlCollectionShouldBeOfTypes, contentPanelType.Name, panelType.Name)), value.GetType().Name); } base.Add(value); } public override void Remove(Control value) { if (value is ToolStripPanel || value is ToolStripContentPanel) { if (!owner.DesignMode) { if (IsReadOnly) throw new NotSupportedException(SR.GetString(SR.ReadonlyControlsCollection)); } } base.Remove(value); } internal override void SetChildIndexInternal(Control child, int newIndex) { if (child is ToolStripPanel || child is ToolStripContentPanel) { if (!owner.DesignMode) { if (IsReadOnly) { throw new NotSupportedException(SR.GetString(SR.ReadonlyControlsCollection)); } } else { // just no-op it at DT. return; } } base.SetChildIndexInternal(child, newIndex); } } } } // 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
- SharedUtils.cs
- ObjectDataSourceChooseTypePanel.cs
- TextEditorCharacters.cs
- PropertyGridEditorPart.cs
- QueryConverter.cs
- UniqueEventHelper.cs
- MessageQuerySet.cs
- HttpModuleCollection.cs
- EdmToObjectNamespaceMap.cs
- NotFiniteNumberException.cs
- LayoutEditorPart.cs
- GatewayIPAddressInformationCollection.cs
- StringReader.cs
- OciLobLocator.cs
- UIElementCollection.cs
- DragStartedEventArgs.cs
- MessageLogTraceRecord.cs
- ProgressBarRenderer.cs
- DomainConstraint.cs
- cookiecollection.cs
- Int32AnimationBase.cs
- FrugalMap.cs
- ValidationHelper.cs
- PerformanceCounterPermissionEntryCollection.cs
- MultiAsyncResult.cs
- GridSplitterAutomationPeer.cs
- TopClause.cs
- InertiaTranslationBehavior.cs
- HandleRef.cs
- Internal.cs
- SelectedDatesCollection.cs
- CellRelation.cs
- StylusButtonEventArgs.cs
- Membership.cs
- HtmlElementCollection.cs
- TemplateBindingExpression.cs
- AccessKeyManager.cs
- CodeConstructor.cs
- PrinterResolution.cs
- StructuredTypeEmitter.cs
- SlipBehavior.cs
- AsyncSerializedWorker.cs
- NestedContainer.cs
- MenuItemBindingCollection.cs
- XmlSchemaAll.cs
- ConnectionsZone.cs
- ADMembershipProvider.cs
- AlphabeticalEnumConverter.cs
- DataGridViewButtonCell.cs
- SiteMapDataSourceDesigner.cs
- MasterPageCodeDomTreeGenerator.cs
- BasicBrowserDialog.cs
- FrameworkTemplate.cs
- PreviewPageInfo.cs
- autovalidator.cs
- PerspectiveCamera.cs
- InvalidPropValue.cs
- TextSchema.cs
- Statements.cs
- ServiceAuthorizationManager.cs
- OrderPreservingMergeHelper.cs
- SqlCacheDependencyDatabase.cs
- DoubleConverter.cs
- Comparer.cs
- XmlCDATASection.cs
- DataBindingCollection.cs
- MutexSecurity.cs
- CryptoApi.cs
- PropertyEmitter.cs
- _FtpControlStream.cs
- counter.cs
- BrowsableAttribute.cs
- TrackBar.cs
- DefaultTextStoreTextComposition.cs
- ColumnCollectionEditor.cs
- SqlCharStream.cs
- Activity.cs
- WindowsToolbarItemAsMenuItem.cs
- ListViewDeleteEventArgs.cs
- ExceptionUtil.cs
- TextLineResult.cs
- UpdateTranslator.cs
- SynthesizerStateChangedEventArgs.cs
- CaseStatement.cs
- XmlValueConverter.cs
- DataRelationCollection.cs
- RowUpdatingEventArgs.cs
- DataTableCollection.cs
- ZipIOFileItemStream.cs
- SafeLibraryHandle.cs
- BreakRecordTable.cs
- UnsafeNativeMethods.cs
- BindingsCollection.cs
- DataGridTemplateColumn.cs
- DispatcherBuilder.cs
- ManagementException.cs
- XPathChildIterator.cs
- CodeTryCatchFinallyStatement.cs
- PartialClassGenerationTask.cs
- ColorMatrix.cs