Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / StandardCommandToolStripMenuItem.cs / 1 / StandardCommandToolStripMenuItem.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms.Design { using System.Design; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Security; using System.Security.Permissions; using System.ComponentModel.Design; using System.Windows.Forms; using System.Drawing; using System.Drawing.Design; using System.Windows.Forms.Design.Behavior; using System.Runtime.InteropServices; using System.Drawing.Drawing2D; ////// /// Associates standard command with ToolStripMenuItem. /// ///internal class StandardCommandToolStripMenuItem : ToolStripMenuItem { private bool _cachedImage = false; private Image _image = null; private CommandID menuID; private IMenuCommandService menuCommandService; private IServiceProvider serviceProvider; private string name; private MenuCommand menuCommand; // Ok to call MenuService.FindComand to find the menuCommand mapping to the appropriated menuID. [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] [SuppressMessage("Microsoft.Security", "CA2102:CatchNonClsCompliantExceptionsInGeneralHandlers")] public StandardCommandToolStripMenuItem(CommandID menuID, string text, string imageName, IServiceProvider serviceProvider) { this.menuID = menuID; this.serviceProvider = serviceProvider; // Findcommand can throw; so we need to catch and disable the command. try { menuCommand = MenuService.FindCommand(menuID); } catch { this.Enabled = false; } this.Text = text; this.name = imageName; RefreshItem(); } public void RefreshItem() { if (menuCommand != null) { this.Visible = menuCommand.Visible; this.Enabled = menuCommand.Enabled; this.Checked = menuCommand.Checked; } } /// /// /// Retrieves the menu editor service, which we cache for speed. /// public IMenuCommandService MenuService { get { if (menuCommandService == null) { menuCommandService = (IMenuCommandService)serviceProvider.GetService(typeof(IMenuCommandService)); } return menuCommandService; } } public override Image Image { // Standard 'catch all - rethrow critical' exception pattern [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] get { // Defer loading the image until we're sure we need it if (!_cachedImage) { _cachedImage = true; try { if (name != null) { _image = new Bitmap(typeof(ToolStripMenuItem), name + ".bmp"); } this.ImageTransparentColor = Color.Magenta; } catch (Exception ex) { if (ClientUtils.IsCriticalException(ex)) { throw; } } catch { } } return _image; } set { _image = value; _cachedImage = true; } } protected override void OnClick(System.EventArgs e) { if (menuCommand != null) { menuCommand.Invoke(); } else if (MenuService != null) { if (MenuService.GlobalInvoke(menuID)) { return; } } } } } // 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
- DataTableNewRowEvent.cs
- Comparer.cs
- sqlstateclientmanager.cs
- NavigateUrlConverter.cs
- EditingCoordinator.cs
- HttpsTransportElement.cs
- _TLSstream.cs
- QueryContinueDragEvent.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- SerialPinChanges.cs
- XmlName.cs
- MailWriter.cs
- HttpListenerContext.cs
- ObjectView.cs
- MediaContextNotificationWindow.cs
- XmlCodeExporter.cs
- RuntimeCompatibilityAttribute.cs
- PreProcessInputEventArgs.cs
- DataGridViewSelectedColumnCollection.cs
- XomlSerializationHelpers.cs
- ContentControl.cs
- ItemList.cs
- DataGridAutoFormat.cs
- BitmapEffectInputConnector.cs
- ClientConfigPaths.cs
- ContentPropertyAttribute.cs
- HttpWebResponse.cs
- BindingExpression.cs
- BindingNavigatorDesigner.cs
- DetailsViewDeleteEventArgs.cs
- AutomationElement.cs
- MessageCredentialType.cs
- NamespaceDisplayAutomationPeer.cs
- ListViewItem.cs
- PointAnimation.cs
- FileCodeGroup.cs
- XmlSerializerOperationFormatter.cs
- _ShellExpression.cs
- Properties.cs
- Freezable.cs
- GlyphingCache.cs
- ImmutablePropertyDescriptorGridEntry.cs
- MissingFieldException.cs
- BufferModeSettings.cs
- DocumentAutomationPeer.cs
- TextParaLineResult.cs
- ProgressBar.cs
- EpmContentSerializerBase.cs
- DispatcherHooks.cs
- MemberAccessException.cs
- GiveFeedbackEvent.cs
- ConfigXmlDocument.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- ToolStripItem.cs
- PrimitiveXmlSerializers.cs
- ContainerCodeDomSerializer.cs
- Button.cs
- MultiDataTrigger.cs
- DbConnectionInternal.cs
- GlyphRun.cs
- MsdtcClusterUtils.cs
- RtfToXamlReader.cs
- SoapInteropTypes.cs
- BufferedStream.cs
- GroupStyle.cs
- TrustLevel.cs
- SwitchLevelAttribute.cs
- PackageDigitalSignatureManager.cs
- XsdDuration.cs
- DataServiceConfiguration.cs
- DataRecordInternal.cs
- Rule.cs
- objectquery_tresulttype.cs
- DefaultTraceListener.cs
- TypeListConverter.cs
- TranslateTransform.cs
- DbProviderSpecificTypePropertyAttribute.cs
- DataGridRelationshipRow.cs
- CLSCompliantAttribute.cs
- DesignerUtils.cs
- WindowsImpersonationContext.cs
- SignatureToken.cs
- IssuanceTokenProviderBase.cs
- DependencyPropertyHelper.cs
- AndCondition.cs
- ElementAtQueryOperator.cs
- isolationinterop.cs
- ToolStrip.cs
- StateChangeEvent.cs
- SchemaElementLookUpTable.cs
- dataprotectionpermission.cs
- RelOps.cs
- Registry.cs
- UnmanagedBitmapWrapper.cs
- WindowsFormsDesignerOptionService.cs
- _BaseOverlappedAsyncResult.cs
- DataGridColumnCollection.cs
- EpmCustomContentDeSerializer.cs
- PipeStream.cs
- ArglessEventHandlerProxy.cs