本文整理汇总了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 ) );
}
示例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));
}
示例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
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例8: GetPosition
public static Point GetPosition(Visual relativeTo)
{
return relativeTo.PointFromScreen(GetPosition());
}
示例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));
}
示例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));
}
示例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;
}
示例12: GetCorrectPosition
private static Point GetCorrectPosition(Visual relativeTo)
{
UnsafeNativeMethods.Win32Point w32Mouse;
UnsafeNativeMethods.GetCursorPos(out w32Mouse);
return relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y));
}