Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / RichTextBoxContextMenu.cs / 1 / RichTextBoxContextMenu.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope="member", Target="System.Windows.Forms.Design.RichTextBoxContextMenu..ctor()")]
namespace System.Windows.Forms.Design {
using Microsoft.Win32;
using System;
using System.Design;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Windows.Forms;
///
/// Context menu for the RichTextBox control
/// We only allow copy/cut/paste of texts
///
internal class RichTextBoxContextMenu : ContextMenu {
private MenuItem undoMenu;
private MenuItem cutMenu;
private MenuItem copyMenu;
private MenuItem pasteMenu;
private MenuItem deleteMenu;
private MenuItem selectAllMenu;
private RichTextBox parent; //the RichTextBox which hosts this context menu
[SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")]
public RichTextBoxContextMenu(RichTextBox parent) : base() {
undoMenu = new MenuItem(SR.GetString(SR.StandardMenuUndo), new EventHandler(undoMenu_Clicked));
cutMenu = new MenuItem(SR.GetString(SR.StandardMenuCut), new EventHandler(cutMenu_Clicked));
copyMenu = new MenuItem(SR.GetString(SR.StandardMenuCopy), new EventHandler(copyMenu_Clicked));
pasteMenu = new MenuItem(SR.GetString(SR.StandardMenuPaste), new EventHandler(pasteMenu_Clicked));
deleteMenu = new MenuItem(SR.GetString(SR.StandardMenuDelete), new EventHandler(deleteMenu_Clicked));
selectAllMenu = new MenuItem(SR.GetString(SR.StandardMenuSelectAll), new EventHandler(selectAllMenu_Clicked));
MenuItem splitter1 = new MenuItem("-");
MenuItem splitter2 = new MenuItem("-");
this.MenuItems.Add(undoMenu);
this.MenuItems.Add(splitter1);
this.MenuItems.Add(cutMenu);
this.MenuItems.Add(copyMenu);
this.MenuItems.Add(pasteMenu);
this.MenuItems.Add(deleteMenu);
this.MenuItems.Add(splitter2);
this.MenuItems.Add(selectAllMenu);
this.parent = parent;
}
///
/// Set the appropriate visibility of the menu items
///
protected override void OnPopup(EventArgs e) {
if (parent.SelectionLength > 0) {
cutMenu.Enabled = true;
copyMenu.Enabled = true;
deleteMenu.Enabled = true;
}
else {
cutMenu.Enabled = false;
copyMenu.Enabled = false;
deleteMenu.Enabled = false;
}
if (Clipboard.GetText() != null) {
pasteMenu.Enabled = true;
}
else {
pasteMenu.Enabled = false;
}
if (parent.CanUndo) {
undoMenu.Enabled = true;
}
else {
undoMenu.Enabled = false;
}
}
private void cutMenu_Clicked(object sender, EventArgs e) {
Clipboard.SetText(parent.SelectedText);
parent.SelectedText = "";
}
private void copyMenu_Clicked(object sender, EventArgs e) {
Clipboard.SetText(parent.SelectedText);
}
private void deleteMenu_Clicked(object sender, EventArgs e) {
parent.SelectedText = "";
}
private void pasteMenu_Clicked(object sender, EventArgs e) {
parent.SelectedText = Clipboard.GetText();
}
private void selectAllMenu_Clicked(object sender, EventArgs e) {
parent.SelectAll();
}
private void undoMenu_Clicked(object sender, EventArgs e) {
parent.Undo();
}
}
}
// 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
- RawKeyboardInputReport.cs
- SymbolMethod.cs
- LinqDataSourceView.cs
- LinqDataSourceDeleteEventArgs.cs
- RegexInterpreter.cs
- XmlElementList.cs
- DocumentViewerAutomationPeer.cs
- QilXmlReader.cs
- EdmToObjectNamespaceMap.cs
- AppSettings.cs
- WebPartTransformer.cs
- RectAnimationBase.cs
- OdbcConnectionPoolProviderInfo.cs
- InputMethodStateTypeInfo.cs
- PropertyPushdownHelper.cs
- SchemaHelper.cs
- SamlAuthorizationDecisionClaimResource.cs
- ZoneButton.cs
- WinCategoryAttribute.cs
- CodeAssignStatement.cs
- TreeView.cs
- mongolianshape.cs
- ImpersonationContext.cs
- GatewayIPAddressInformationCollection.cs
- Executor.cs
- WorkflowInstanceUnhandledExceptionRecord.cs
- ServiceParser.cs
- Win32MouseDevice.cs
- SqlUserDefinedAggregateAttribute.cs
- SocketPermission.cs
- CompilationUnit.cs
- DesignerCategoryAttribute.cs
- Compress.cs
- OracleDataReader.cs
- ContextCorrelationInitializer.cs
- ExpandoClass.cs
- DataViewManager.cs
- DrawingContext.cs
- Rfc2898DeriveBytes.cs
- DataViewManager.cs
- EntityDataSourceDesignerHelper.cs
- RecordBuilder.cs
- HtmlElementEventArgs.cs
- OletxCommittableTransaction.cs
- WebPartDisplayModeCollection.cs
- RequestDescription.cs
- KeyEvent.cs
- IdentityHolder.cs
- HtmlHistory.cs
- HttpHandlersSection.cs
- MultipartIdentifier.cs
- Wildcard.cs
- CompositeControl.cs
- HostingEnvironmentWrapper.cs
- XmlSchemaComplexContentExtension.cs
- TextSegment.cs
- CryptographicAttribute.cs
- ThreadStaticAttribute.cs
- MinimizableAttributeTypeConverter.cs
- safelinkcollection.cs
- DivideByZeroException.cs
- DecimalKeyFrameCollection.cs
- CustomAttributeSerializer.cs
- ProbeMatches11.cs
- MetadataHelper.cs
- CaseInsensitiveHashCodeProvider.cs
- TraceLevelStore.cs
- HtmlWindow.cs
- BuildProviderCollection.cs
- X509CertificateTrustedIssuerElementCollection.cs
- HttpApplication.cs
- OrderedDictionaryStateHelper.cs
- RegexGroup.cs
- CharEntityEncoderFallback.cs
- TextClipboardData.cs
- HasCopySemanticsAttribute.cs
- HotCommands.cs
- RouteUrlExpressionBuilder.cs
- StorageMappingFragment.cs
- SubstitutionDesigner.cs
- BuildProvider.cs
- RuleSettingsCollection.cs
- TraceEventCache.cs
- PersonalizationStateInfo.cs
- InputScopeConverter.cs
- xml.cs
- OdbcConnection.cs
- SchemaReference.cs
- PriorityItem.cs
- DataControlButton.cs
- SoapSchemaMember.cs
- StreamResourceInfo.cs
- PixelShader.cs
- ReferenceAssemblyAttribute.cs
- DataBindingCollection.cs
- DbInsertCommandTree.cs
- DefaultExpressionVisitor.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- _IPv6Address.cs
- CompatibleIComparer.cs