ScreenToClient() public static method

public static ScreenToClient ( FrameworkElement element, IntPoint point ) : Point
element System.Windows.FrameworkElement
point IntPoint
return Point
コード例 #1
0
        public static Point ScreenToClient(FrameworkElement element, IntPoint point)
        {
            PresentationSource source = PresentationSource.FromVisual(element);

            Win32Point winPt = new Win32Point(point.X, point.Y);

            NativeMethods.ScreenToClient(((HwndSource)source).Handle, ref winPt);

            Point offset = source.CompositionTarget.TransformFromDevice.Transform(new Point(winPt.x, winPt.y));

            return(source.RootVisual.TransformToDescendant(element).Transform(offset));
        }
コード例 #2
0
        private void AnimateBounds(IntRect screenBounds)
        {
            this.screenBounds = screenBounds;
            this.bounds       = NativeMethods.ScreenToClient(this, this.screenBounds);

            TimeSpan duration = TimeSpan.FromSeconds(.2);

            this.BoundsOffsetX.AnimateTo(this.bounds.Left, duration);
            this.BoundsOffsetY.AnimateTo(this.bounds.Top, duration);

            this.BoundsWidth.AnimateTo(this.bounds.Width, duration);
            this.BoundsHeight.AnimateTo(this.bounds.Height, duration);

            this.Dimensions.Visibility = Visibility.Visible;
            this.Dimensions.Text       = string.Format(@"{0} x {1}", this.screenBounds.Width, this.screenBounds.Height);
        }
コード例 #3
0
        protected void UpdateBounds(IntRect screenBounds, IntPoint point)
        {

            Rect bounds = NativeMethods.ScreenToClient(this, screenBounds);
            Point screenPoint = NativeMethods.ScreenToClient(this, point);

            this.Bounds.Width = bounds.Width;
            this.Bounds.Height = bounds.Height;


            this.Bounds.Margin = new Thickness(bounds.Left, bounds.Top, 0, 0);

            this.CenterY.Height = new GridLength(Math.Max(screenPoint.Y - bounds.Y, 0));
            this.CenterX.Width = new GridLength(Math.Max(screenPoint.X - bounds.X, 0));

            if (this.StretchMode == StretchMode.EastWest)
                this.Dimensions.Text = string.Format(@"{0}", screenBounds.Width);
            else if (this.StretchMode == StretchMode.NorthSouth)
                this.Dimensions.Text = string.Format(@"{0}", screenBounds.Height);
            else
                this.Dimensions.Text = string.Format(@"{0} x {1}", screenBounds.Width, screenBounds.Height);
        }