Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ContextMenuStrip.cs / 1305376 / ContextMenuStrip.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using System.ComponentModel; using System.Drawing; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; ///this class is just a conceptual wrapper around ToolStripDropDownMenu. [ ComVisible(true), ClassInterface(ClassInterfaceType.AutoDispatch), DefaultEvent("Opening"), SRDescription(SR.DescriptionContextMenuStrip) ] public class ContextMenuStrip : ToolStripDropDownMenu { /// /// Summary of ContextMenuStrip. /// public ContextMenuStrip(IContainer container) : base() { // this constructor ensures ContextMenuStrip is disposed properly since its not parented to the form. if (container == null) { throw new ArgumentNullException("container"); } container.Add(this); } public ContextMenuStrip(){ } protected override void Dispose(bool disposing) { base.Dispose(disposing); } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SRDescription(SR.ContextMenuStripSourceControlDescr) ] public Control SourceControl { [UIPermission(SecurityAction.Demand, Window=UIPermissionWindow.AllWindows)] get { return SourceControlInternal; } } // minimal Clone implementation for DGV support only. internal ContextMenuStrip Clone() { // VERY limited support for cloning. ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); // copy over events contextMenuStrip.Events.AddHandlers(this.Events); contextMenuStrip.AutoClose = AutoClose; contextMenuStrip.AutoSize = AutoSize; contextMenuStrip.Bounds = Bounds; contextMenuStrip.ImageList = ImageList; contextMenuStrip.ShowCheckMargin = ShowCheckMargin; contextMenuStrip.ShowImageMargin = ShowImageMargin; // copy over relevant properties for (int i = 0; i < Items.Count; i++) { ToolStripItem item = Items[i]; if (item is ToolStripSeparator) { contextMenuStrip.Items.Add(new ToolStripSeparator()); } else if (item is ToolStripMenuItem) { ToolStripMenuItem menuItem = item as ToolStripMenuItem; contextMenuStrip.Items.Add(menuItem.Clone()); } } return contextMenuStrip; } // internal overload so we know whether or not to show mnemonics. internal void ShowInternal(Control source, Point location, bool isKeyboardActivated) { Show(source, location); // if we were activated by keyboard - show mnemonics. if (isKeyboardActivated) { ToolStripManager.ModalMenuFilter.Instance.ShowUnderlines = true; } } internal void ShowInTaskbar(int x, int y) { // we need to make ourselves a topmost window WorkingAreaConstrained = false; Rectangle bounds = CalculateDropDownLocation(new Point(x,y), ToolStripDropDownDirection.AboveLeft); Rectangle screenBounds = Screen.FromRectangle(bounds).Bounds; if (bounds.Y < screenBounds.Y) { bounds = CalculateDropDownLocation(new Point(x,y), ToolStripDropDownDirection.BelowLeft); } else if (bounds.X < screenBounds.X) { bounds = CalculateDropDownLocation(new Point(x,y), ToolStripDropDownDirection.AboveRight); } bounds = WindowsFormsUtils.ConstrainToBounds(screenBounds, bounds); Show(bounds.X, bounds.Y); } protected override void SetVisibleCore(bool visible) { if (!visible) { WorkingAreaConstrained = true; } base.SetVisibleCore(visible); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using System.ComponentModel; using System.Drawing; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; ///this class is just a conceptual wrapper around ToolStripDropDownMenu. [ ComVisible(true), ClassInterface(ClassInterfaceType.AutoDispatch), DefaultEvent("Opening"), SRDescription(SR.DescriptionContextMenuStrip) ] public class ContextMenuStrip : ToolStripDropDownMenu { /// /// Summary of ContextMenuStrip. /// public ContextMenuStrip(IContainer container) : base() { // this constructor ensures ContextMenuStrip is disposed properly since its not parented to the form. if (container == null) { throw new ArgumentNullException("container"); } container.Add(this); } public ContextMenuStrip(){ } protected override void Dispose(bool disposing) { base.Dispose(disposing); } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SRDescription(SR.ContextMenuStripSourceControlDescr) ] public Control SourceControl { [UIPermission(SecurityAction.Demand, Window=UIPermissionWindow.AllWindows)] get { return SourceControlInternal; } } // minimal Clone implementation for DGV support only. internal ContextMenuStrip Clone() { // VERY limited support for cloning. ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); // copy over events contextMenuStrip.Events.AddHandlers(this.Events); contextMenuStrip.AutoClose = AutoClose; contextMenuStrip.AutoSize = AutoSize; contextMenuStrip.Bounds = Bounds; contextMenuStrip.ImageList = ImageList; contextMenuStrip.ShowCheckMargin = ShowCheckMargin; contextMenuStrip.ShowImageMargin = ShowImageMargin; // copy over relevant properties for (int i = 0; i < Items.Count; i++) { ToolStripItem item = Items[i]; if (item is ToolStripSeparator) { contextMenuStrip.Items.Add(new ToolStripSeparator()); } else if (item is ToolStripMenuItem) { ToolStripMenuItem menuItem = item as ToolStripMenuItem; contextMenuStrip.Items.Add(menuItem.Clone()); } } return contextMenuStrip; } // internal overload so we know whether or not to show mnemonics. internal void ShowInternal(Control source, Point location, bool isKeyboardActivated) { Show(source, location); // if we were activated by keyboard - show mnemonics. if (isKeyboardActivated) { ToolStripManager.ModalMenuFilter.Instance.ShowUnderlines = true; } } internal void ShowInTaskbar(int x, int y) { // we need to make ourselves a topmost window WorkingAreaConstrained = false; Rectangle bounds = CalculateDropDownLocation(new Point(x,y), ToolStripDropDownDirection.AboveLeft); Rectangle screenBounds = Screen.FromRectangle(bounds).Bounds; if (bounds.Y < screenBounds.Y) { bounds = CalculateDropDownLocation(new Point(x,y), ToolStripDropDownDirection.BelowLeft); } else if (bounds.X < screenBounds.X) { bounds = CalculateDropDownLocation(new Point(x,y), ToolStripDropDownDirection.AboveRight); } bounds = WindowsFormsUtils.ConstrainToBounds(screenBounds, bounds); Show(bounds.X, bounds.Y); } protected override void SetVisibleCore(bool visible) { if (!visible) { WorkingAreaConstrained = true; } base.SetVisibleCore(visible); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ContentPosition.cs
- XmlWriter.cs
- ContextStaticAttribute.cs
- QueryConverter.cs
- XmlDataProvider.cs
- OutputCacheSettings.cs
- IChannel.cs
- XmlWrappingReader.cs
- WriterOutput.cs
- ContextProperty.cs
- WorkerRequest.cs
- BasicCellRelation.cs
- SignatureHelper.cs
- WinFormsSecurity.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- FormatConvertedBitmap.cs
- SafeSerializationManager.cs
- ReadOnlyCollection.cs
- XmlSchemaImporter.cs
- XmlArrayAttribute.cs
- TextServicesDisplayAttributePropertyRanges.cs
- UniqueConstraint.cs
- DataGridViewAutoSizeModeEventArgs.cs
- XmlDictionaryReaderQuotas.cs
- wgx_commands.cs
- XmlObjectSerializerWriteContextComplex.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- ObjectDataSourceWizardForm.cs
- DataPointer.cs
- ObjectStateFormatter.cs
- WmlValidatorAdapter.cs
- SchemaType.cs
- StylusButtonCollection.cs
- XmlWriterSettings.cs
- BaseValidator.cs
- XhtmlTextWriter.cs
- SiteMap.cs
- NamedPipeAppDomainProtocolHandler.cs
- userdatakeys.cs
- Configuration.cs
- DebugView.cs
- StatusBarItem.cs
- QilLiteral.cs
- PresentationAppDomainManager.cs
- StylusPointPropertyInfoDefaults.cs
- PageCanvasSize.cs
- MemberAccessException.cs
- Span.cs
- InvalidFilterCriteriaException.cs
- SQLByteStorage.cs
- XsltConvert.cs
- ServiceReflector.cs
- HScrollBar.cs
- CryptoHandle.cs
- BitmapScalingModeValidation.cs
- ExecutionContext.cs
- unsafenativemethodstextservices.cs
- DataGridViewColumnCollection.cs
- Compiler.cs
- ProcessModuleCollection.cs
- TaiwanLunisolarCalendar.cs
- ColumnCollection.cs
- Stylus.cs
- ParseChildrenAsPropertiesAttribute.cs
- BadImageFormatException.cs
- DesignerRegion.cs
- ChildDocumentBlock.cs
- ListQueryResults.cs
- WaitForChangedResult.cs
- GroupAggregateExpr.cs
- WorkflowInstanceProvider.cs
- RequiredArgumentAttribute.cs
- SingleObjectCollection.cs
- AssemblyLoader.cs
- SimpleType.cs
- AsymmetricCryptoHandle.cs
- AnimationStorage.cs
- DataBindingCollectionEditor.cs
- ObjectSet.cs
- unsafeIndexingFilterStream.cs
- PixelFormat.cs
- _KerberosClient.cs
- EnterpriseServicesHelper.cs
- DesignTimeVisibleAttribute.cs
- SchemaExporter.cs
- DataTableNewRowEvent.cs
- ConfigXmlText.cs
- KeyFrames.cs
- SqlTransaction.cs
- SharedStatics.cs
- DBSqlParserTableCollection.cs
- BitmapEffect.cs
- COM2PictureConverter.cs
- ProviderMetadata.cs
- MonikerHelper.cs
- RoleManagerEventArgs.cs
- InputManager.cs
- ProfileInfo.cs
- RadioButtonList.cs
- DefaultBinder.cs