Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ToolStripSettings.cs / 1305376 / ToolStripSettings.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using System.Configuration; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Drawing; using System.Text; using System.Text.RegularExpressions; ////// /// A settings class used by the ToolStripManager to save toolstrip settings. /// internal class ToolStripSettings : ApplicationSettingsBase { internal ToolStripSettings(string settingsKey) : base(settingsKey) {} [UserScopedSetting] [DefaultSettingValue("true")] public bool IsDefault { get { return (bool) this["IsDefault"]; } set { this["IsDefault"] = value; } } [UserScopedSetting] public string ItemOrder { get { return this["ItemOrder"] as string; } set { this["ItemOrder"] = value; } } [UserScopedSetting] public string Name { get { return this["Name"] as string; } set { this["Name"] = value; } } [UserScopedSetting] [DefaultSettingValue("0,0")] public Point Location { get { return (Point) this["Location"]; } set { this["Location"] = value; } } [UserScopedSetting] [DefaultSettingValue("0,0")] public Size Size { get { return (Size) this["Size"]; } set { this["Size"] = value; } } [UserScopedSetting] public string ToolStripPanelName { get { return this["ToolStripPanelName"] as string; } set { this["ToolStripPanelName"] = value; } } [UserScopedSetting] [DefaultSettingValue("true")] public bool Visible { get { return (bool) this["Visible"]; } set { this["Visible"] = value; } } public override void Save() { this.IsDefault = false; base.Save(); } } ////// /// Helper class used by ToolStripManager that implements most of the logic to save out and apply /// settings for toolstrips on a form. /// internal class ToolStripSettingsManager { private Form form; private string formKey; internal ToolStripSettingsManager(Form owner, string formKey) { this.form = owner; this.formKey = formKey; } internal void Load() { ArrayList savedToolStripSettingsObjects = new ArrayList(); foreach (ToolStrip toolStrip in FindToolStrips(true, form.Controls)) { if (toolStrip != null && !string.IsNullOrEmpty(toolStrip.Name)) { ToolStripSettings toolStripSettings = new ToolStripSettings(GetSettingsKey(toolStrip)); // Check if we have settings saved out for this toolstrip. If so, add it to our apply list. if (!toolStripSettings.IsDefault) { savedToolStripSettingsObjects.Add(new SettingsStub(toolStripSettings)); } } } ApplySettings(savedToolStripSettingsObjects); } internal void Save() { foreach (ToolStrip toolStrip in FindToolStrips(true, form.Controls)) { if (toolStrip != null && !string.IsNullOrEmpty(toolStrip.Name)) { ToolStripSettings toolStripSettings = new ToolStripSettings(GetSettingsKey(toolStrip)); SettingsStub stub = new SettingsStub(toolStrip); toolStripSettings.ItemOrder = stub.ItemOrder; toolStripSettings.Name = stub.Name; toolStripSettings.Location = stub.Location; toolStripSettings.Size = stub.Size; toolStripSettings.ToolStripPanelName = stub.ToolStripPanelName; toolStripSettings.Visible = stub.Visible; toolStripSettings.Save(); } } } internal static string GetItemOrder(ToolStrip toolStrip) { StringBuilder itemNames = new StringBuilder(toolStrip.Items.Count); for (int i = 0; i < toolStrip.Items.Count; i++) { itemNames.Append((toolStrip.Items[i].Name == null) ? "null" : toolStrip.Items[i].Name); if (i != toolStrip.Items.Count - 1) { itemNames.Append(","); } } return itemNames.ToString(); } private void ApplySettings(ArrayList toolStripSettingsToApply) { if (toolStripSettingsToApply.Count == 0) { return; } SuspendAllLayout(form); // iterate through all the toolstrips and build up a hash of where the items // are right now. DictionaryitemLocationHash = BuildItemOriginationHash(); // build up a hash of where we want the ToolStrips to go Dictionary
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ArrangedElement.cs
- ExponentialEase.cs
- CompilationUnit.cs
- _FtpDataStream.cs
- ActiveXSite.cs
- SQLInt32Storage.cs
- ExtenderControl.cs
- PropertyGrid.cs
- RoleGroup.cs
- TreeViewTemplateSelector.cs
- AesCryptoServiceProvider.cs
- BitmapEffectrendercontext.cs
- UriExt.cs
- StylusPointPropertyUnit.cs
- BoundingRectTracker.cs
- BCLDebug.cs
- ReadOnlyHierarchicalDataSource.cs
- XPathDocument.cs
- AsyncResult.cs
- UnmanagedMemoryStream.cs
- OutputCacheProfileCollection.cs
- IndexedGlyphRun.cs
- URLString.cs
- MultiTrigger.cs
- CellPartitioner.cs
- ConfigurationErrorsException.cs
- CriticalExceptions.cs
- CompoundFileStorageReference.cs
- DataSourceXmlTextReader.cs
- SignerInfo.cs
- DeploymentSection.cs
- SQLMoney.cs
- DeferredTextReference.cs
- CodeCatchClauseCollection.cs
- ConfigXmlWhitespace.cs
- DynamicValidatorEventArgs.cs
- SiteMapHierarchicalDataSourceView.cs
- DesigntimeLicenseContextSerializer.cs
- GenericWebPart.cs
- CapabilitiesState.cs
- AuthenticationConfig.cs
- EdmMember.cs
- ComplexPropertyEntry.cs
- HttpServerVarsCollection.cs
- ProgressBar.cs
- ApplicationDirectoryMembershipCondition.cs
- ReadOnlyAttribute.cs
- PartManifestEntry.cs
- SapiGrammar.cs
- UserNameSecurityTokenParameters.cs
- _DisconnectOverlappedAsyncResult.cs
- EFDataModelProvider.cs
- Header.cs
- InputScopeAttribute.cs
- JsonFormatReaderGenerator.cs
- PointLightBase.cs
- XamlFigureLengthSerializer.cs
- PolicyLevel.cs
- IUnknownConstantAttribute.cs
- BitmapEffectGeneralTransform.cs
- TextEditorCharacters.cs
- MiniModule.cs
- FixedNode.cs
- MessageBox.cs
- Operators.cs
- DataGridRow.cs
- DefaultCommandConverter.cs
- BlurBitmapEffect.cs
- PrimitiveCodeDomSerializer.cs
- DocumentApplication.cs
- TextRangeProviderWrapper.cs
- BindingGroup.cs
- ListView.cs
- WindowsListViewGroupHelper.cs
- DataGridViewRowCollection.cs
- WorkflowTransactionService.cs
- XmlAttributeProperties.cs
- recordstatefactory.cs
- DataGridViewCellPaintingEventArgs.cs
- DataBinding.cs
- HtmlEmptyTagControlBuilder.cs
- EntityDataSourceDataSelection.cs
- DataControlHelper.cs
- VirtualPathUtility.cs
- AbsoluteQuery.cs
- LifetimeMonitor.cs
- HeaderCollection.cs
- PolygonHotSpot.cs
- SctClaimSerializer.cs
- SurrogateSelector.cs
- XamlHostingSectionGroup.cs
- BorderGapMaskConverter.cs
- DeleteMemberBinder.cs
- TemplateBindingExpressionConverter.cs
- EventHandlerList.cs
- StringReader.cs
- HwndSourceParameters.cs
- ClientSponsor.cs
- ProtocolsInstallComponent.cs
- ResponseBodyWriter.cs