Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / WinForms / Managed / System / WinForms / ToolStripSettings.cs / 1 / 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
- AsyncStreamReader.cs
- DoubleLinkList.cs
- DataGridViewComboBoxCell.cs
- Win32MouseDevice.cs
- GeometryHitTestResult.cs
- Image.cs
- SortedDictionary.cs
- ResourceAttributes.cs
- _CacheStreams.cs
- TableSectionStyle.cs
- Int64Converter.cs
- Command.cs
- PropertyTabAttribute.cs
- SqlDataReaderSmi.cs
- ListParaClient.cs
- IgnoreFileBuildProvider.cs
- HttpModuleActionCollection.cs
- LayoutManager.cs
- metrodevice.cs
- GraphicsState.cs
- HtmlInputSubmit.cs
- AppSettingsExpressionBuilder.cs
- CachedBitmap.cs
- CodeTypeDeclarationCollection.cs
- X509SubjectKeyIdentifierClause.cs
- ManipulationCompletedEventArgs.cs
- GradientSpreadMethodValidation.cs
- base64Transforms.cs
- Bidi.cs
- LogicalExpressionTypeConverter.cs
- ExpressionEditorAttribute.cs
- FlowDocumentScrollViewer.cs
- ProfilePropertyNameValidator.cs
- FileFormatException.cs
- DeploymentSectionCache.cs
- SafeFindHandle.cs
- AssemblyUtil.cs
- HwndMouseInputProvider.cs
- QueryActivatableWorkflowsCommand.cs
- Column.cs
- Metafile.cs
- AppliedDeviceFiltersEditor.cs
- WindowsPrincipal.cs
- Helpers.cs
- ZeroOpNode.cs
- XamlRtfConverter.cs
- TrustLevel.cs
- ConfigDefinitionUpdates.cs
- RIPEMD160Managed.cs
- RegexMatch.cs
- FeatureSupport.cs
- QueryGenerator.cs
- DataSvcMapFileSerializer.cs
- Errors.cs
- ServerValidateEventArgs.cs
- XmlDocumentFragment.cs
- FixUpCollection.cs
- FontDifferentiator.cs
- SessionEndingCancelEventArgs.cs
- RemoteCryptoRsaServiceProvider.cs
- XmlConvert.cs
- AndCondition.cs
- EmptyReadOnlyDictionaryInternal.cs
- EdmComplexPropertyAttribute.cs
- InvalidOleVariantTypeException.cs
- WhileDesigner.xaml.cs
- VectorConverter.cs
- Point3DValueSerializer.cs
- RemoteArgument.cs
- Crc32.cs
- EventLogPermissionEntry.cs
- CriticalExceptions.cs
- CharStorage.cs
- TextEditor.cs
- WebCategoryAttribute.cs
- ObjectViewQueryResultData.cs
- DeclaredTypeElementCollection.cs
- PtsContext.cs
- Camera.cs
- XmlProcessingInstruction.cs
- PartialList.cs
- FixedSOMContainer.cs
- RemotingSurrogateSelector.cs
- Types.cs
- ButtonBaseAdapter.cs
- ServiceHost.cs
- DatagridviewDisplayedBandsData.cs
- Bezier.cs
- TextBoxAutomationPeer.cs
- InvalidFilterCriteriaException.cs
- FontEmbeddingManager.cs
- AnnotationResource.cs
- Border.cs
- hwndwrapper.cs
- HostingEnvironmentWrapper.cs
- TreeViewItemAutomationPeer.cs
- PersonalizationEntry.cs
- CryptoKeySecurity.cs
- ObjectConverter.cs
- ColumnResizeAdorner.cs