Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / IntegerCollectionEditor.cs / 1 / IntegerCollectionEditor.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- #define NEEDHELPBUTTON /* */ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope="member", Target="System.Windows.Forms.Design.IntegerCollectionEditor..ctor(System.Type)")] namespace System.Windows.Forms.Design { using System.Design; using System.ComponentModel; using System; using System.Collections; using Microsoft.Win32; using System.ComponentModel.Design; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; using System.Globalization; using System.Diagnostics.CodeAnalysis; ////// /// The IntegerCollectionEditor is a collection editor that is specifically /// designed to edit collections containing Integers. /// internal class IntegerCollectionEditor : CollectionEditor { public IntegerCollectionEditor(Type type) : base(type) { } ////// /// Creates a new form to show the current collection. You may inherit /// from CollectionForm to provide your own form. /// protected override CollectionForm CreateCollectionForm() { return new IntegerCollectionForm(this); } ////// /// protected override string HelpTopic { get { return "net.ComponentModel.IntegerCollectionEditor"; } } ///Gets the help topic to display for the dialog help button or pressing F1. Override to /// display a different help topic. ////// /// IntegerCollectionEditor allows visible editing of a integer array. Each line in /// the edit box is an array entry. /// private class IntegerCollectionForm : CollectionForm { private Label instruction = new Label(); private TextBox textEntry = new TextBox(); private Button okButton = new Button(); private Button cancelButton = new Button(); #if NEEDHELPBUTTON private Button helpButton = new Button(); #endif private IntegerCollectionEditor editor = null; ////// /// Constructs a StringCollectionForm. /// public IntegerCollectionForm(CollectionEditor editor) : base(editor) { this.editor = (IntegerCollectionEditor) editor; InitializeComponent(); } private void Edit1_keyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { cancelButton.PerformClick(); e.Handled = true; } } private void HelpButton_click(object sender, EventArgs e) { editor.ShowHelp(); } private void Form_HelpRequested(object sender, HelpEventArgs e) { editor.ShowHelp(); } ////// /// NOTE: The following code is required by the form /// designer. It can be modified using the form editor. Do not /// modify it using the code editor. /// [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")] private void InitializeComponent() { instruction.Location = new Point(4, 7); instruction.Size = new Size(422, 14); instruction.TabIndex = 0; instruction.TabStop = false; instruction.Text = SR.GetString(SR.IntegerCollectionEditorInstruction); textEntry.Location = new Point(4, 22); textEntry.Size = new Size(422, 244); textEntry.TabIndex = 0; textEntry.Text = ""; textEntry.AcceptsTab = false; textEntry.AcceptsReturn = true; textEntry.AutoSize = false; textEntry.Multiline = true; textEntry.ScrollBars = ScrollBars.Both; textEntry.WordWrap = false; textEntry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right; textEntry.KeyDown += new KeyEventHandler(this.Edit1_keyDown); #if NEEDHELPBUTTON okButton.Location = new Point(185, 274); #else okButton.Location = new Point(264, 274); #endif okButton.Size = new Size(75, 23); okButton.TabIndex = 1; okButton.Text = SR.GetString(SR.IntegerCollectionEditorOKCaption); okButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; okButton.DialogResult = DialogResult.OK; okButton.Click += new EventHandler(this.OKButton_click); #if NEEDHELPBUTTON cancelButton.Location = new Point(264, 274); #else cancelButton.Location = new Point(343, 274); #endif cancelButton.Size = new Size(75, 23); cancelButton.TabIndex = 2; cancelButton.Text = SR.GetString(SR.IntegerCollectionEditorCancelCaption); cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; cancelButton.DialogResult = DialogResult.Cancel; #if NEEDHELPBUTTON helpButton.Location = new Point(343, 274); helpButton.Size = new Size(75, 23); helpButton.TabIndex = 3; helpButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; helpButton.Text = SR.GetString(SR.IntegerCollectionEditorHelpCaption); #endif this.Location = new Point(7, 7); this.Text = SR.GetString(SR.IntegerCollectionEditorTitle); this.AcceptButton = okButton; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleDimensions = new SizeF(6, 13); this.CancelButton = cancelButton; this.ClientSize = new Size(429, 307); this.MaximizeBox = false; this.MinimizeBox = false; this.ControlBox = false; this.ShowInTaskbar = false; // VSWhidbey 94233: Force the dialog to open using FormStartPosition.CenterScreen. this.StartPosition = FormStartPosition.CenterScreen; this.MinimumSize = new Size(300, 200); helpButton.Click += new EventHandler(this.HelpButton_click); this.HelpRequested += new HelpEventHandler(this.Form_HelpRequested); this.Controls.Clear(); this.Controls.AddRange(new Control[] { instruction, textEntry, okButton, cancelButton, #if NEEDHELPBUTTON helpButton #endif }); } ////// /// Commits the changes to the editor. /// private void OKButton_click(object sender, EventArgs e) { char[] delims = new char[] {'\n'}; char[] trims = new char[] {'\r'}; string[] strings = textEntry.Text.Split(delims); object[] curItems = Items; int nItems = strings.Length; // If the final line is blank, we don't want to create an item from it // if (strings.Length > 0 && strings[strings.Length - 1].Length == 0) { nItems--; } int[] currentValues = new int[nItems]; for (int i = 0; i < nItems; i++) { strings[i] = strings[i].Trim(trims); try { currentValues[i] = Int32.Parse(strings[i], CultureInfo.CurrentCulture); } catch (Exception ex) { DisplayError(ex); if (ClientUtils.IsCriticalException(ex)) { throw; } } catch { Debug.Fail("non-CLS compliant exception"); } } bool dirty = true; if (nItems == curItems.Length) { int i; for (i = 0; i < nItems; ++i) { if (!currentValues[i].Equals((int)curItems[i])) { break; } } if (i == nItems) dirty = false; } if (!dirty) { DialogResult = DialogResult.Cancel; return; } object[] values = new object[nItems]; for (int i = 0; i < nItems; i++) { values[i] = currentValues[i]; } Items = values; } //// This is called when the value property in the CollectionForm has changed. // In it you should update your user interface to reflect the current value. // // protected override void OnEditValueChanged() { object[] items = Items; string text = string.Empty; for (int i = 0; i < items.Length; i++) { if (items[i] is int) { text += ((Int32)items[i]).ToString(CultureInfo.CurrentCulture); if (i != items.Length - 1) { text += "\r\n"; } } } textEntry.Text = text; } } } } // 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
- ConditionChanges.cs
- PlainXmlWriter.cs
- GridViewDeletedEventArgs.cs
- WindowsGraphicsWrapper.cs
- RouteValueExpressionBuilder.cs
- RawAppCommandInputReport.cs
- CachedFontFamily.cs
- TagPrefixCollection.cs
- BrowserCapabilitiesCodeGenerator.cs
- KeySpline.cs
- TabPanel.cs
- UniformGrid.cs
- DataBoundControlAdapter.cs
- FileChangesMonitor.cs
- ThicknessAnimationBase.cs
- TemplatePagerField.cs
- CodeParameterDeclarationExpression.cs
- Stream.cs
- SqlClientWrapperSmiStreamChars.cs
- PrivilegedConfigurationManager.cs
- HtmlEmptyTagControlBuilder.cs
- CommentEmitter.cs
- HeaderedItemsControl.cs
- Stacktrace.cs
- FormatterConverter.cs
- TabRenderer.cs
- QilInvokeLateBound.cs
- TCEAdapterGenerator.cs
- QueryableFilterUserControl.cs
- WhitespaceRuleLookup.cs
- MetadataArtifactLoaderResource.cs
- DataGridViewAccessibleObject.cs
- StorageConditionPropertyMapping.cs
- DtrList.cs
- ViewRendering.cs
- _PooledStream.cs
- IndexerNameAttribute.cs
- XmlQueryContext.cs
- ProtocolViolationException.cs
- LayoutEditorPart.cs
- SqlConnectionPoolProviderInfo.cs
- SafeHandles.cs
- NullableDoubleAverageAggregationOperator.cs
- SecurityAlgorithmSuiteConverter.cs
- DataGridViewDataErrorEventArgs.cs
- _IPv6Address.cs
- ScriptControlManager.cs
- ExceptionUtil.cs
- StringValueConverter.cs
- Sql8ExpressionRewriter.cs
- BindingCompleteEventArgs.cs
- ColumnWidthChangingEvent.cs
- DesigntimeLicenseContext.cs
- AuthenticationModulesSection.cs
- SplitterCancelEvent.cs
- DbConnectionPoolOptions.cs
- HttpApplicationFactory.cs
- EtwTrace.cs
- DataListItemEventArgs.cs
- Win32KeyboardDevice.cs
- OutputCacheSettings.cs
- SqlConnection.cs
- ObfuscationAttribute.cs
- DEREncoding.cs
- CallSiteHelpers.cs
- NamedElement.cs
- XmlSchemaAnyAttribute.cs
- WindowsToolbarItemAsMenuItem.cs
- Condition.cs
- Lease.cs
- ConfigurationElementProperty.cs
- EventSourceCreationData.cs
- IfAction.cs
- GridItem.cs
- WebZone.cs
- BuilderPropertyEntry.cs
- UiaCoreProviderApi.cs
- EventRoute.cs
- DataBoundLiteralControl.cs
- DataControlLinkButton.cs
- StrokeDescriptor.cs
- BitmapSizeOptions.cs
- VirtualDirectoryMappingCollection.cs
- ExpressionDumper.cs
- HealthMonitoringSectionHelper.cs
- HighlightComponent.cs
- SecurityKeyEntropyMode.cs
- Canvas.cs
- ThreadStateException.cs
- TableRowCollection.cs
- LinkGrep.cs
- ProviderConnectionPointCollection.cs
- TypeDescriptor.cs
- ComponentConverter.cs
- GetLedgerRequest.cs
- DocobjHost.cs
- ZipPackage.cs
- UpdateDelegates.Generated.cs
- URL.cs
- SerializableTypeCodeDomSerializer.cs