Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / ExtensionWindowResizeGrip.cs / 1305376 / ExtensionWindowResizeGrip.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; //This class is visual representation of ResizeGrip like control, which is used with ExtenstionWindows to allow //resizing. Actual resize logic is handled by ExtensionSurface class [TemplatePart(Name = "PART_ResizeGrip")] class ExtensionWindowResizeGrip : Control { public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(DrawingBrush), typeof(ExtensionWindowResizeGrip)); ExtensionWindow parent; ExtensionSurface surface; Point offset; [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline, Justification = "Overriding metadata for dependency properties in static constructor is the way suggested by WPF")] static ExtensionWindowResizeGrip() { DefaultStyleKeyProperty.OverrideMetadata( typeof(ExtensionWindowResizeGrip), new FrameworkPropertyMetadata(typeof(ExtensionWindowResizeGrip))); } public DrawingBrush Icon { get { return (DrawingBrush)GetValue(IconProperty); } set { SetValue(IconProperty, value); } } protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); if (this.parent.IsResizable) { this.Cursor = Cursors.SizeNWSE; this.offset = e.GetPosition(this); CaptureMouse(); } } protected override void OnMouseMove(MouseEventArgs args) { base.OnMouseMove(args); if (args.LeftButton == MouseButtonState.Pressed && this.IsMouseCaptured) { Point currentPosition = Mouse.GetPosition(this.parent); currentPosition.Offset(this.offset.X, this.offset.Y); Size newSize = new Size(); newSize.Width = Math.Min(Math.Max(this.parent.MinWidth, currentPosition.X), this.parent.MaxWidth); newSize.Height = Math.Min(Math.Max(this.parent.MinHeight, currentPosition.Y), this.parent.MaxHeight); System.Diagnostics.Debug.WriteLine("NewSize = (" + newSize.Width + "," + newSize.Height + ")"); this.surface.SetSize(this.parent, newSize); } } protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnMouseLeftButtonUp(e); Mouse.OverrideCursor = null; Mouse.Capture(null); } protected override void OnVisualParentChanged(DependencyObject oldParent) { base.OnVisualParentChanged(oldParent); if (!DesignerProperties.GetIsInDesignMode(this) && !ExtensionWindow.TryGetParentExtensionWindow(this, out this.parent, out this.surface)) { Fx.Assert("ExtensionWindowHeader cannot be used outside ExtensionWindow"); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; //This class is visual representation of ResizeGrip like control, which is used with ExtenstionWindows to allow //resizing. Actual resize logic is handled by ExtensionSurface class [TemplatePart(Name = "PART_ResizeGrip")] class ExtensionWindowResizeGrip : Control { public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(DrawingBrush), typeof(ExtensionWindowResizeGrip)); ExtensionWindow parent; ExtensionSurface surface; Point offset; [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline, Justification = "Overriding metadata for dependency properties in static constructor is the way suggested by WPF")] static ExtensionWindowResizeGrip() { DefaultStyleKeyProperty.OverrideMetadata( typeof(ExtensionWindowResizeGrip), new FrameworkPropertyMetadata(typeof(ExtensionWindowResizeGrip))); } public DrawingBrush Icon { get { return (DrawingBrush)GetValue(IconProperty); } set { SetValue(IconProperty, value); } } protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); if (this.parent.IsResizable) { this.Cursor = Cursors.SizeNWSE; this.offset = e.GetPosition(this); CaptureMouse(); } } protected override void OnMouseMove(MouseEventArgs args) { base.OnMouseMove(args); if (args.LeftButton == MouseButtonState.Pressed && this.IsMouseCaptured) { Point currentPosition = Mouse.GetPosition(this.parent); currentPosition.Offset(this.offset.X, this.offset.Y); Size newSize = new Size(); newSize.Width = Math.Min(Math.Max(this.parent.MinWidth, currentPosition.X), this.parent.MaxWidth); newSize.Height = Math.Min(Math.Max(this.parent.MinHeight, currentPosition.Y), this.parent.MaxHeight); System.Diagnostics.Debug.WriteLine("NewSize = (" + newSize.Width + "," + newSize.Height + ")"); this.surface.SetSize(this.parent, newSize); } } protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnMouseLeftButtonUp(e); Mouse.OverrideCursor = null; Mouse.Capture(null); } protected override void OnVisualParentChanged(DependencyObject oldParent) { base.OnVisualParentChanged(oldParent); if (!DesignerProperties.GetIsInDesignMode(this) && !ExtensionWindow.TryGetParentExtensionWindow(this, out this.parent, out this.surface)) { Fx.Assert("ExtensionWindowHeader cannot be used outside ExtensionWindow"); } } } } // 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
- BitmapMetadataEnumerator.cs
- FormatException.cs
- ParserOptions.cs
- SimpleFileLog.cs
- RadioButtonRenderer.cs
- EditorPartCollection.cs
- Columns.cs
- XsdBuilder.cs
- ObjectAnimationBase.cs
- _DisconnectOverlappedAsyncResult.cs
- AccessText.cs
- ClientFormsAuthenticationCredentials.cs
- DbParameterCollectionHelper.cs
- UnicastIPAddressInformationCollection.cs
- XmlSchemaSimpleTypeRestriction.cs
- MethodRental.cs
- FrameSecurityDescriptor.cs
- StreamUpgradeInitiator.cs
- PropertyItemInternal.cs
- PathStreamGeometryContext.cs
- RootAction.cs
- MDIClient.cs
- DataGridViewUtilities.cs
- VerificationException.cs
- StoreItemCollection.Loader.cs
- SecurityHeaderTokenResolver.cs
- TextDecorationCollection.cs
- GridViewRowCollection.cs
- PreProcessInputEventArgs.cs
- RefType.cs
- XPathSelectionIterator.cs
- WebBrowserUriTypeConverter.cs
- ACL.cs
- InteropTrackingRecord.cs
- SynchronizationValidator.cs
- OleDbRowUpdatedEvent.cs
- DataBindingCollection.cs
- InputBindingCollection.cs
- HotSpotCollection.cs
- InputManager.cs
- XmlTextAttribute.cs
- HttpWebRequest.cs
- KernelTypeValidation.cs
- UMPAttributes.cs
- XmlSchemaSequence.cs
- ShutDownListener.cs
- ToolStripControlHost.cs
- EntityContainerEmitter.cs
- SingleTagSectionHandler.cs
- PageCatalogPart.cs
- ObjectAnimationBase.cs
- MustUnderstandSoapException.cs
- ThousandthOfEmRealPoints.cs
- _NegoState.cs
- NullRuntimeConfig.cs
- ParagraphResult.cs
- Misc.cs
- QueryBranchOp.cs
- FixedPageProcessor.cs
- PrinterSettings.cs
- KeyPressEvent.cs
- TransformConverter.cs
- ObjectDataSourceDesigner.cs
- RSAProtectedConfigurationProvider.cs
- WebPartCloseVerb.cs
- HtmlInputPassword.cs
- TemplateBindingExpression.cs
- InvalidWMPVersionException.cs
- SortFieldComparer.cs
- ShaderEffect.cs
- SubMenuStyleCollectionEditor.cs
- TypedDataSetSchemaImporterExtensionFx35.cs
- MemoryStream.cs
- DataGridViewSelectedRowCollection.cs
- SystemKeyConverter.cs
- InvokeAction.cs
- SystemSounds.cs
- EntityDataSourceViewSchema.cs
- TextTrailingCharacterEllipsis.cs
- AssemblyHash.cs
- NameValueSectionHandler.cs
- DataControlLinkButton.cs
- ImpersonationOption.cs
- XmlReflectionMember.cs
- RtfControlWordInfo.cs
- IriParsingElement.cs
- ProxyFragment.cs
- TableLayoutStyleCollection.cs
- BeginStoryboard.cs
- HtmlInputControl.cs
- SymmetricKeyWrap.cs
- SearchForVirtualItemEventArgs.cs
- CharEntityEncoderFallback.cs
- ExternalCalls.cs
- CacheHelper.cs
- NegationPusher.cs
- TemplateControlCodeDomTreeGenerator.cs
- TextDpi.cs
- TableRowGroup.cs
- XpsManager.cs