Code:
/ FX-1434 / FX-1434 / 1.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
- ValuePatternIdentifiers.cs
- SiteMapSection.cs
- ExplicitDiscriminatorMap.cs
- TypeUsageBuilder.cs
- IndexingContentUnit.cs
- DebugView.cs
- KeyedHashAlgorithm.cs
- EntityContainerEmitter.cs
- ColorComboBox.cs
- StringAttributeCollection.cs
- TextBoxBase.cs
- DataList.cs
- ObjectParameterCollection.cs
- XsdDuration.cs
- DataGridViewSelectedCellCollection.cs
- UpdateTranslator.cs
- XmlSchemaDocumentation.cs
- XmlSchemaValidator.cs
- WebPartConnectionsConnectVerb.cs
- MouseActionValueSerializer.cs
- Group.cs
- ScriptingProfileServiceSection.cs
- XmlArrayAttribute.cs
- CodeSubDirectory.cs
- Ref.cs
- Attachment.cs
- ChangePassword.cs
- MaterialGroup.cs
- IISMapPath.cs
- MobileListItem.cs
- DecimalStorage.cs
- CustomErrorsSection.cs
- ToolStripDropDownClosingEventArgs.cs
- IDispatchConstantAttribute.cs
- NetMsmqBindingCollectionElement.cs
- TraceFilter.cs
- DocumentSequenceHighlightLayer.cs
- ReaderWriterLock.cs
- KeyFrames.cs
- basevalidator.cs
- SqlEnums.cs
- WebPartCollection.cs
- CompatibleIComparer.cs
- RC2.cs
- FontInfo.cs
- CorrelationTokenTypeConvertor.cs
- XmlSerializableServices.cs
- PhysicalFontFamily.cs
- AnnotationHelper.cs
- xmlfixedPageInfo.cs
- ISO2022Encoding.cs
- TdsParserSessionPool.cs
- Scalars.cs
- Journaling.cs
- Msmq4SubqueuePoisonHandler.cs
- PartialArray.cs
- VisualStyleTypesAndProperties.cs
- ConfigurationErrorsException.cs
- BaseValidator.cs
- TextTreeText.cs
- CultureTableRecord.cs
- ObjectQueryExecutionPlan.cs
- FileUtil.cs
- DateTimePicker.cs
- ImageMapEventArgs.cs
- ExecutionEngineException.cs
- PassportAuthentication.cs
- WindowsSolidBrush.cs
- TabControlToolboxItem.cs
- EncryptedHeader.cs
- ConfigurationException.cs
- EntityDataSourceSelectedEventArgs.cs
- dsa.cs
- SqlBulkCopyColumnMappingCollection.cs
- StringFreezingAttribute.cs
- ImageUrlEditor.cs
- ProxyManager.cs
- HtmlFormWrapper.cs
- TypeResolvingOptions.cs
- MissingSatelliteAssemblyException.cs
- VisualStateGroup.cs
- ErrorWrapper.cs
- objectquery_tresulttype.cs
- ClosableStream.cs
- TypeConvertions.cs
- FileDialogCustomPlacesCollection.cs
- ButtonField.cs
- SocketAddress.cs
- TextSelection.cs
- SBCSCodePageEncoding.cs
- TextEditorContextMenu.cs
- ToolStripKeyboardHandlingService.cs
- DesignerActionTextItem.cs
- TraceListener.cs
- FileVersionInfo.cs
- SectionXmlInfo.cs
- ScrollEventArgs.cs
- RawMouseInputReport.cs
- FixedSOMPageConstructor.cs
- SafeNativeMethods.cs