當前位置: 首頁>>代碼示例>>C#>>正文


C# Visual.PointFromScreen方法代碼示例

本文整理匯總了C#中System.Windows.Media.Visual.PointFromScreen方法的典型用法代碼示例。如果您正苦於以下問題:C# Visual.PointFromScreen方法的具體用法?C# Visual.PointFromScreen怎麽用?C# Visual.PointFromScreen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Media.Visual的用法示例。


在下文中一共展示了Visual.PointFromScreen方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetPosition

        /// <summary>
        /// Uses Win32 API to return mouse pointer position relative to a specific Visual. This
        /// function is provided because WPF's mouse API becomes unreliable under certain circumstances,
        /// like during drag-drop operations.
        /// </summary>
        /// <param name="relativeTo">Visual against which mouse position is reported</param>
        /// <returns>Mouse pointer location relative to passed in Visual</returns>
        public static Point GetPosition(Visual relativeTo)
        {
            Win32.Point w32Mouse = new Win32.Point();

            Win32.GetCursorPos( ref w32Mouse );

            return relativeTo.PointFromScreen( new Point( w32Mouse.X, w32Mouse.Y ) );
        }
開發者ID:dxm007,項目名稱:Droppy,代碼行數:15,代碼來源:MouseEx.cs

示例2: GetMousePosition

        /// <summary>
        /// Returns the mouse cursor location.  This method is necessary during 
        /// a drag-drop operation because the WPF mechanisms for retrieving the
        /// cursor coordinates are unreliable.
        /// </summary>
        /// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
        public static Point GetMousePosition(Visual relativeTo)
        {
            Win32Point mouse = new Win32Point();
            GetCursorPos(ref mouse);

            // Using PointFromScreen instead of Dan Crevier's code (commented out below)
            // is a bug fix created by William J. Roberts.  Read his comments about the fix
            // here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx
            return relativeTo.PointFromScreen(new Point((double)mouse.X, (double)mouse.Y));
        }
開發者ID:nydehi,項目名稱:onesync,代碼行數:16,代碼來源:MouseUtilities.cs

示例3: GetMousePosition

        /// <summary>
        /// Returns the mouse cursor location.  This method is necessary during 
        /// a drag-drop operation because the WPF mechanisms for retrieving the
        /// cursor coordinates are unreliable.
        /// </summary>
        /// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
        public static Point GetMousePosition( Visual relativeTo )
        {
            Win32Point mouse = new Win32Point();
            GetCursorPos( ref mouse );

            // Using PointFromScreen instead of Dan Crevier's code (commented out below)
            // is a bug fix created by William J. Roberts.  Read his comments about the fix
            // here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx
            return relativeTo.PointFromScreen( new Point( (double)mouse.X, (double)mouse.Y ) );

            #region Commented Out
            //System.Windows.Interop.HwndSource presentationSource =
            //    (System.Windows.Interop.HwndSource)PresentationSource.FromVisual( relativeTo );
            //ScreenToClient( presentationSource.Handle, ref mouse );
            //GeneralTransform transform = relativeTo.TransformToAncestor( presentationSource.RootVisual );
            //Point offset = transform.Transform( new Point( 0, 0 ) );
            //return new Point( mouse.X - offset.X, mouse.Y - offset.Y );
            #endregion // Commented Out
        }
開發者ID:iarray,項目名稱:LoveMusic,代碼行數:25,代碼來源:MouseUtilities.cs

示例4: CloneUsingXaml

        /* NOTE: CloneUsingXaml is temporarily removed.
           The method is currently not used. To avoid any confusions in the API documentation it is
           commented out because it would be listed as extension method for every other type.
     
        /// <summary>
        /// Clones an object using XAML serialization rules.
        /// </summary>
        /// <param name="obj">The <see cref="Object"/> to be cloned.</param>
        /// <returns>
        /// A clone of <paramref name="obj"/> where all public fields are cloned (deep copy). Fields or
        /// events are not copied and have their default values.
        /// </returns>
        public static Object CloneUsingXaml(this object obj)
        {
            // NOTE: This helper method is based on the tip provided by Mike Hillberg.
            // See http://blogs.msdn.com/mikehillberg/archive/2007/05/01/CloneWithXamlWriterXamlReader.aspx

            string xaml = XamlWriter.Save(obj);
            return XamlReader.Load(new XmlTextReader(new StringReader(xaml)));
        }
        */


        /// <summary>
        /// Gets location of the mouse cursor relative to the specified <see cref="Visual"/>.
        /// </summary>
        /// <param name="visual">The <see cref="Visual"/>.</param>
        /// <returns>The mouse position relative to <paramref name="visual"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="visual"/> is <see langword="null"/>.
        /// </exception>
        public static Point GetMousePosition(Visual visual)
        {
            if (visual == null)
                throw new ArgumentNullException(nameof(visual));

            POINT pointNative = new POINT();
            Win32.GetCursorPos(ref pointNative);
            Point point = new Point(pointNative.X, pointNative.Y);

            // Convert mouse position from screen coordinates into local coordinates of visual.
            return visual.PointFromScreen(point);
        }
開發者ID:Zolniu,項目名稱:DigitalRune,代碼行數:43,代碼來源:WindowsHelper.Desktop.cs

示例5: GetBoundsInLocalCoordinates

 private static Rect GetBoundsInLocalCoordinates(Visual visual, Rect boundsInScreenCoordinates)
 {
     var localBoundsUpperLeft = visual.PointFromScreen(new Point(boundsInScreenCoordinates.X, boundsInScreenCoordinates.Y));
     var localBoundsLowerRight = visual.PointFromScreen(new Point(
                                                     boundsInScreenCoordinates.X + boundsInScreenCoordinates.Width,
                                                     boundsInScreenCoordinates.Y + boundsInScreenCoordinates.Height));
     return new Rect(localBoundsUpperLeft, localBoundsLowerRight);
 }
開發者ID:osin-vladimir,項目名稱:EyeX,代碼行數:8,代碼來源:WpfCrawler.cs

示例6: GetCursorPos

 public static Point GetCursorPos(Visual relativeTo)
 {
     Win32Point pt = new Win32Point();
     GetCursorPos(ref pt);
     return relativeTo.PointFromScreen(new Point((double)pt.X, (double)pt.Y));
 }
開發者ID:QuocHuy7a10,項目名稱:Arianrhod,代碼行數:6,代碼來源:MouseHelper.cs

示例7: GetMousePosition

 /// <summary>
 /// Returns the mouse cursor location.  This method is necessary during
 /// a drag-drop operation because the WPF mechanisms for retrieving the
 /// cursor coordinates are unreliable.
 /// </summary>
 /// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
 public static Point GetMousePosition(Visual relativeTo)
 {
     Win32Point mouse = new Win32Point();
     GetCursorPos(ref mouse);
     return relativeTo.PointFromScreen(new Point((double)mouse.X, (double)mouse.Y));
 }
開發者ID:networkelements,項目名稱:Outopos,代碼行數:12,代碼來源:Extensions.cs

示例8: GetPosition

 public static Point GetPosition(Visual relativeTo)
 {
     return relativeTo.PointFromScreen(GetPosition());
 }
開發者ID:NGenesis,項目名稱:VrPlayer.Trackers.OSVRTracker,代碼行數:4,代碼來源:MouseUtilities.cs

示例9: CorrectGetPosition

 public static Point CorrectGetPosition(Visual relativeTo)
 {
     var w32Mouse = new NativeMethods.Win32Point();
     NativeMethods.GetCursorPos(ref w32Mouse);
     return relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y));
 }
開發者ID:OronDF343,項目名稱:Sky-Jukebox,代碼行數:6,代碼來源:MouseUtils.cs

示例10: GetPosition

 internal static Point GetPosition(Visual relativeTo)
 {
     var w32Mouse = new User32.POINT();
     GetCursorPos(ref w32Mouse);
     return relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y));
 }
開發者ID:sbambach,項目名稱:ATF,代碼行數:6,代碼來源:Win32Calls.cs

示例11: GetPixelSnappingOffset

 private static Point GetPixelSnappingOffset(Visual visual, Visual rootVisual)
 {
     var point = new Point();
     if (rootVisual != null)
     {
         var transform = visual.TransformToAncestor(rootVisual) as Transform;
         if ((transform != null) && transform.Value.HasInverse)
         {
             point = visual.PointFromScreen(visual.PointToScreen(point));
         }
     }
     
     return point;
 }
開發者ID:sbambach,項目名稱:ATF,代碼行數:14,代碼來源:Icon.cs

示例12: GetCorrectPosition

 private static Point GetCorrectPosition(Visual relativeTo)
 {
     UnsafeNativeMethods.Win32Point w32Mouse;
     UnsafeNativeMethods.GetCursorPos(out w32Mouse);
     return relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y));
 }
開發者ID:D-Key,項目名稱:LordJZ,代碼行數:6,代碼來源:BaseWindow.cs


注:本文中的System.Windows.Media.Visual.PointFromScreen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。