Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / PropertyGridInternal / HotCommands.cs / 1555735 / HotCommands.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms.PropertyGridInternal { using System.Text; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Windows.Forms; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using Microsoft.Win32; internal class HotCommands : PropertyGrid.SnappableControl { private object component; private DesignerVerb[] verbs; private LinkLabel label; private bool allowVisible = true; private int optimalHeight = -1; [ SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters") // HotCommands window is not visible // So we don't have to localize its text. ] internal HotCommands(PropertyGrid owner) : base(owner) { this.Text = "Command Pane"; } public virtual bool AllowVisible { get { return allowVisible; } set { if (this.allowVisible != value) { this.allowVisible = value; if (value && WouldBeVisible) this.Visible = true; else this.Visible = false; } } } public override Rectangle DisplayRectangle { get { Size sz = ClientSize; return new Rectangle(4, 4, sz.Width - 8, sz.Height - 8); } } public LinkLabel Label { get { if (label == null) { label = new LinkLabel(); label.Dock = DockStyle.Fill; label.LinkBehavior = LinkBehavior.AlwaysUnderline; // use default LinkLabel colors for regular, active, and visited label.DisabledLinkColor = SystemColors.ControlDark; label.LinkClicked += new LinkLabelLinkClickedEventHandler(this.LinkClicked); this.Controls.Add(label); } return label; } } public virtual bool WouldBeVisible { get { return (component != null); } } public override int GetOptimalHeight(int width) { if (optimalHeight == -1) { int lineHeight = (int)(1.5 * Font.Height); int verbCount = 0; if (verbs != null) { verbCount = verbs.Length; } optimalHeight = verbCount * lineHeight + 8; } return optimalHeight; } public override int SnapHeightRequest(int request) { return request; } private void LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { if (!e.Link.Enabled) { return; } ((DesignerVerb)e.Link.LinkData).Invoke(); } catch (Exception ex) { RTLAwareMessageBox.Show(this, ex.Message, SR.GetString(SR.PBRSErrorTitle), MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, 0); } } private void OnCommandChanged(object sender, EventArgs e) { SetupLabel(); } protected override void OnGotFocus(EventArgs e) { Label.FocusInternal(); Label.Invalidate(); } protected override void OnFontChanged(EventArgs e) { base.OnFontChanged(e); optimalHeight = -1; } internal void SetColors(Color background, Color normalText, Color link, Color activeLink, Color visitedLink, Color disabledLink) { Label.BackColor = background; Label.ForeColor = normalText; Label.LinkColor = link; Label.ActiveLinkColor = activeLink; Label.VisitedLinkColor = visitedLink; Label.DisabledLinkColor = disabledLink; } public void Select(bool forward) { Label.FocusInternal(); } public virtual void SetVerbs(object component, DesignerVerb[] verbs) { if (this.verbs != null) { for (int i = 0; i < this.verbs.Length; i++){ this.verbs[i].CommandChanged -= new EventHandler(this.OnCommandChanged); } this.component = null; this.verbs = null; } if (component == null || verbs == null || verbs.Length == 0) { Visible = false; Label.Links.Clear(); Label.Text = null; } else { this.component = component; this.verbs = verbs; for (int i = 0; i < verbs.Length; i++){ verbs[i].CommandChanged += new EventHandler(this.OnCommandChanged); } if (allowVisible) { Visible = true; } SetupLabel(); } optimalHeight = -1; } private void SetupLabel() { Label.Links.Clear(); StringBuilder sb = new StringBuilder(); Point[] links = new Point[verbs.Length]; int charLoc = 0; bool firstVerb = true; for (int i=0; i// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.Windows.Forms.PropertyGridInternal { using System.Text; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Windows.Forms; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using Microsoft.Win32; internal class HotCommands : PropertyGrid.SnappableControl { private object component; private DesignerVerb[] verbs; private LinkLabel label; private bool allowVisible = true; private int optimalHeight = -1; [ SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters") // HotCommands window is not visible // So we don't have to localize its text. ] internal HotCommands(PropertyGrid owner) : base(owner) { this.Text = "Command Pane"; } public virtual bool AllowVisible { get { return allowVisible; } set { if (this.allowVisible != value) { this.allowVisible = value; if (value && WouldBeVisible) this.Visible = true; else this.Visible = false; } } } public override Rectangle DisplayRectangle { get { Size sz = ClientSize; return new Rectangle(4, 4, sz.Width - 8, sz.Height - 8); } } public LinkLabel Label { get { if (label == null) { label = new LinkLabel(); label.Dock = DockStyle.Fill; label.LinkBehavior = LinkBehavior.AlwaysUnderline; // use default LinkLabel colors for regular, active, and visited label.DisabledLinkColor = SystemColors.ControlDark; label.LinkClicked += new LinkLabelLinkClickedEventHandler(this.LinkClicked); this.Controls.Add(label); } return label; } } public virtual bool WouldBeVisible { get { return (component != null); } } public override int GetOptimalHeight(int width) { if (optimalHeight == -1) { int lineHeight = (int)(1.5 * Font.Height); int verbCount = 0; if (verbs != null) { verbCount = verbs.Length; } optimalHeight = verbCount * lineHeight + 8; } return optimalHeight; } public override int SnapHeightRequest(int request) { return request; } private void LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { if (!e.Link.Enabled) { return; } ((DesignerVerb)e.Link.LinkData).Invoke(); } catch (Exception ex) { RTLAwareMessageBox.Show(this, ex.Message, SR.GetString(SR.PBRSErrorTitle), MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, 0); } } private void OnCommandChanged(object sender, EventArgs e) { SetupLabel(); } protected override void OnGotFocus(EventArgs e) { Label.FocusInternal(); Label.Invalidate(); } protected override void OnFontChanged(EventArgs e) { base.OnFontChanged(e); optimalHeight = -1; } internal void SetColors(Color background, Color normalText, Color link, Color activeLink, Color visitedLink, Color disabledLink) { Label.BackColor = background; Label.ForeColor = normalText; Label.LinkColor = link; Label.ActiveLinkColor = activeLink; Label.VisitedLinkColor = visitedLink; Label.DisabledLinkColor = disabledLink; } public void Select(bool forward) { Label.FocusInternal(); } public virtual void SetVerbs(object component, DesignerVerb[] verbs) { if (this.verbs != null) { for (int i = 0; i < this.verbs.Length; i++){ this.verbs[i].CommandChanged -= new EventHandler(this.OnCommandChanged); } this.component = null; this.verbs = null; } if (component == null || verbs == null || verbs.Length == 0) { Visible = false; Label.Links.Clear(); Label.Text = null; } else { this.component = component; this.verbs = verbs; for (int i = 0; i < verbs.Length; i++){ verbs[i].CommandChanged += new EventHandler(this.OnCommandChanged); } if (allowVisible) { Visible = true; } SetupLabel(); } optimalHeight = -1; } private void SetupLabel() { Label.Links.Clear(); StringBuilder sb = new StringBuilder(); Point[] links = new Point[verbs.Length]; int charLoc = 0; bool firstVerb = true; for (int i=0; i
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RepeatInfo.cs
- Compress.cs
- KeyValueConfigurationElement.cs
- NotCondition.cs
- IArgumentProvider.cs
- NativeMethods.cs
- FontSource.cs
- HostExecutionContextManager.cs
- TextTreeRootNode.cs
- PackageDigitalSignatureManager.cs
- ScriptResourceAttribute.cs
- NavigationWindow.cs
- TempFiles.cs
- uribuilder.cs
- InvalidComObjectException.cs
- DeferredElementTreeState.cs
- TrackingAnnotationCollection.cs
- DataGridColumnEventArgs.cs
- NullableDoubleAverageAggregationOperator.cs
- ReferenceEqualityComparer.cs
- CaseInsensitiveOrdinalStringComparer.cs
- DynamicILGenerator.cs
- CodePageEncoding.cs
- UnsafeNativeMethodsCLR.cs
- HtmlElementErrorEventArgs.cs
- DefaultEvaluationContext.cs
- XmlNavigatorStack.cs
- CreateCardRequest.cs
- MobileTextWriter.cs
- documentsequencetextview.cs
- EdmToObjectNamespaceMap.cs
- MatrixCamera.cs
- IgnoreFlushAndCloseStream.cs
- CatalogPartCollection.cs
- BamlRecordHelper.cs
- FloaterParaClient.cs
- EpmSyndicationContentSerializer.cs
- DataGridViewCell.cs
- DropDownList.cs
- ShapeTypeface.cs
- KnownIds.cs
- AttributeCollection.cs
- UserInitiatedRoutedEventPermissionAttribute.cs
- TypeHelpers.cs
- MobileSysDescriptionAttribute.cs
- DependentTransaction.cs
- SingleAnimationUsingKeyFrames.cs
- TextTreeInsertUndoUnit.cs
- NotifyIcon.cs
- SocketPermission.cs
- EventLogSession.cs
- ReadContentAsBinaryHelper.cs
- XmlSchemaIdentityConstraint.cs
- HttpHandlerAction.cs
- DebuggerService.cs
- SecurityException.cs
- LogLogRecord.cs
- AttributeProviderAttribute.cs
- DbException.cs
- ExceptionTrace.cs
- SystemIcmpV4Statistics.cs
- exports.cs
- ExternalException.cs
- TreeViewAutomationPeer.cs
- PrimitiveDataContract.cs
- SqlMethodAttribute.cs
- BitmapDecoder.cs
- BypassElementCollection.cs
- ISSmlParser.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- Inflater.cs
- ToolStrip.cs
- BitmapEffectGeneralTransform.cs
- ValueChangedEventManager.cs
- XmlSchemaInclude.cs
- Stack.cs
- ADRoleFactory.cs
- AccessedThroughPropertyAttribute.cs
- WebEventTraceProvider.cs
- Pair.cs
- XPathArrayIterator.cs
- ContextActivityUtils.cs
- JoinTreeNode.cs
- CheckBoxList.cs
- References.cs
- MetadataCache.cs
- HttpCookieCollection.cs
- HtmlInputControl.cs
- ReflectionPermission.cs
- ProfilePropertyNameValidator.cs
- DynamicControlParameter.cs
- NativeMethods.cs
- SerializationFieldInfo.cs
- StringResourceManager.cs
- ISessionStateStore.cs
- CompiledQuery.cs
- TableDetailsRow.cs
- MenuRenderer.cs
- PropertyCollection.cs
- LinearGradientBrush.cs