本文整理汇总了C#中System.Windows.FrameworkElement.PointToScreen方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.PointToScreen方法的具体用法?C# FrameworkElement.PointToScreen怎么用?C# FrameworkElement.PointToScreen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.PointToScreen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetScreenBounds
/// <summary>
/// Cache the screen bounds of the monitor in which the targetElement is rendered.
/// </summary>
/// <param name="itemsPresenter"></param>
/// <returns></returns>
public static Rect GetScreenBounds(FrameworkElement targetElement, Popup popup)
{
if (targetElement != null)
{
Rect targetBoundingBox = new Rect(targetElement.PointToScreen(new Point()),
targetElement.PointToScreen(new Point(targetElement.RenderSize.Width, targetElement.RenderSize.Height)));
NativeMethods.RECT rect = new NativeMethods.RECT() { top = 0, bottom = 0, left = 0, right = 0 };
NativeMethods.RECT nativeBounds = NativeMethods.FromRect(targetBoundingBox);
IntPtr monitor = NativeMethods.MonitorFromRect(ref nativeBounds, NativeMethods.MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero)
{
NativeMethods.MONITORINFOEX monitorInfo = new NativeMethods.MONITORINFOEX();
monitorInfo.cbSize = Marshal.SizeOf(typeof(NativeMethods.MONITORINFOEX));
NativeMethods.GetMonitorInfo(new HandleRef(null, monitor), monitorInfo);
// WPF Popup special cases MenuItem to be restricted to work area
// Hence Ribbon applies the same rules as well.
if (popup.TemplatedParent is RibbonMenuItem)
{
rect = monitorInfo.rcWork;
}
else if (popup.TemplatedParent is RibbonMenuButton)
{
rect = monitorInfo.rcMonitor;
}
}
return NativeMethods.ToRect(rect);
}
return Rect.Empty;
}
示例2: IsItemMidpointInContainer
public static bool IsItemMidpointInContainer(FrameworkElement container, FrameworkElement target)
{
var containerTopLeft = container.PointToScreen(new Point());
var itemTopLeft = target.PointToScreen(new Point());
double topBoundary = containerTopLeft.Y;
double bottomBoundary = topBoundary + container.ActualHeight;
double leftBoundary = containerTopLeft.X;
double rightBoundary = leftBoundary + container.ActualWidth;
//use midpoint of item (width or height divided by 2)
double itemLeft = itemTopLeft.X + (target.ActualWidth / 2);
double itemTop = itemTopLeft.Y + (target.ActualHeight / 2);
if (itemTop < topBoundary || bottomBoundary < itemTop) {
//Midpoint of target is outside of top or bottom
return false;
}
if (itemLeft < leftBoundary || rightBoundary < itemLeft) {
//Midpoint of target is outside of left or right
return false;
}
return true;
}
示例3: ShowErrorTooltip
public void ShowErrorTooltip(FrameworkElement attachTo, UIElement errorElement)
{
if (attachTo == null)
throw new ArgumentNullException("attachTo");
if (errorElement == null)
throw new ArgumentNullException("errorElement");
AttachedErrorBalloon b = new AttachedErrorBalloon(attachTo, errorElement);
Point pos = attachTo.PointToScreen(new Point(0, attachTo.ActualHeight));
b.Left = pos.X;
b.Top = pos.Y - 8;
b.Focusable = false;
ITopLevelWindowService windowService = services.GetService<ITopLevelWindowService>();
ITopLevelWindow ownerWindow = (windowService != null) ? windowService.GetTopLevelWindow(attachTo) : null;
if (ownerWindow != null) {
ownerWindow.SetOwner(b);
}
b.Show();
if (ownerWindow != null) {
ownerWindow.Activate();
}
b.AttachEvents();
}
示例4: EditTranslationDialog
public EditTranslationDialog(TranslationItem translationItem, Action<TranslationItem> callback, FrameworkElement owinElement = null)
{
InitializeComponent();
if (translationItem == null || callback == null)
{
DialogResult = null;
Close();
return;
}
_title = Title;
if (owinElement != null)
{
try
{
var pointFromScreen = owinElement.PointToScreen(new Point(-5, 0));
WindowStartupLocation = WindowStartupLocation.Manual;
var top = pointFromScreen.Y;
var left = pointFromScreen.X;
Top = top > 0 ? top : Top;
Left = left > 0 ? left : Left;
MaxHeight = SystemParameters.PrimaryScreenHeight - Top - 50;
Width = owinElement.ActualWidth + 50;
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
_originalText = translationItem.TextWithOverflow;
TranslationTextBox.Text = translationItem.TextWithOverflow;
TranslationTextBox.TextChanged += (sender, args) =>
{
var changed = string.Compare(_originalText, TranslationTextBox.Text, StringComparison.InvariantCulture) != 0;
Title = changed ? _title + "*" : _title;
};
TranslationTextBox.Focus();
var caretIndex = TranslationTextBox.Text.Length;
if(caretIndex > -1)
TranslationTextBox.CaretIndex = caretIndex;
TranslationTextBox.ScrollToEnd();
CancelButton.Click += (sender, args) =>
{
DialogResult = false;
Close();
};
ReplaceButton.Click += (sender, args) =>
{
var item = new TranslationItem(translationItem) {Text = TranslationTextBox.Text};
DialogResult = true;
callback(item);
Close();
};
}
示例5: Invoke
/// <summary>
/// ウィンドウ操作を実行します。
/// </summary>
/// <param name="action">実行するウィンドウ操作。</param>
/// <param name="source">操作を実行しようとしている UI 要素。この要素をホストするウィンドウに対し、<paramref name="action"/> 操作が実行されます。</param>
public static void Invoke(this WindowAction action, FrameworkElement source)
{
var window = Window.GetWindow(source);
if (window == null) return;
switch (action)
{
case WindowAction.Active:
window.Activate();
break;
case WindowAction.Close:
window.Close();
break;
case WindowAction.Maximize:
window.WindowState = WindowState.Maximized;
break;
case WindowAction.Minimize:
window.WindowState = WindowState.Minimized;
break;
case WindowAction.Normalize:
window.WindowState = WindowState.Normal;
break;
case WindowAction.OpenSystemMenu:
var point = source.PointToScreen(new Point(0, source.ActualHeight));
SystemCommands.ShowSystemMenu(window, point);
break;
}
}
示例6: QueryContinueDrag
/// <summary>
/// ドラッグ中処理
/// </summary>
/// <param name="owner"></param>
public void QueryContinueDrag(FrameworkElement owner)
{
if (Ghost != null) {
var p = CursorInfo.GetNowPosition(owner);
var loc = owner.PointFromScreen(owner.PointToScreen(new Point(0, 0)));
Point renderedLocation = owner.TranslatePoint(new Point(0, 0), Window.GetWindow(owner));
Ghost.LeftOffset = p.X - loc.X - renderedLocation.X;
Ghost.TopOffset = p.Y - loc.Y - renderedLocation.Y;
}
}
示例7: FindValues
public void FindValues(FrameworkElement container, FrameworkElement target)
{
var containerTopLeft = container.PointToScreen(new Point());
var itemTopLeft = target.PointToScreen(new Point());
_topBoundary = containerTopLeft.Y;
_bottomBoundary = _topBoundary + container.ActualHeight;
_leftBoundary = containerTopLeft.X;
_rightBoundary = _leftBoundary + container.ActualWidth;
_itemLeft = itemTopLeft.X + (target.ActualWidth / 2);
_itemTop = itemTopLeft.Y + (target.ActualHeight / 2);
}
示例8: FindValues
private static void FindValues(FrameworkElement container, FrameworkElement target)
{
var containerTopLeft = container.PointToScreen(new Point());
var itemTopLeft = target.PointToScreen(new Point());
_topBoundary = containerTopLeft.Y;
_bottomBoundary = _topBoundary + container.ActualHeight;
_leftBoundary = containerTopLeft.X;
_rightBoundary = _leftBoundary + container.ActualWidth;
//use midpoint of item (width or height divided by 2)
_itemLeft = itemTopLeft.X + (target.ActualWidth / 2);
_itemTop = itemTopLeft.Y + (target.ActualHeight / 2);
}
示例9: SetupPositionAndSize
private void SetupPositionAndSize(double positionTargetX, FrameworkElement positionAndSizeBase)
{
Width = positionAndSizeBase.ActualWidth;
Height = positionAndSizeBase.ActualHeight;
Point mousePosition = Mouse.GetPosition(positionAndSizeBase);
double windowOffsetX = positionTargetX - mousePosition.X;
//TODO calculate value
int windowHeaderCenterY = 7;
Point targetPosition = positionAndSizeBase.PointToScreen(new Point(-windowOffsetX, mousePosition.Y - windowHeaderCenterY));
Left = targetPosition.X;
Top = targetPosition.Y;
}
示例10: DockIconsLayer
/// <summary>
/// Constructor</summary>
/// <param name="element">Source element to create window for</param>
public DockIconsLayer(FrameworkElement element)
{
ShowInTaskbar = false;
ShowActivated = false;
WindowStyle = WindowStyle.None;
AllowsTransparency = true;
Background = Brushes.Transparent;
Topmost = true;
m_canvas = new Canvas();
Content = m_canvas;
WindowStartupLocation = WindowStartupLocation.Manual;
Point position = element.PointToScreen(new Point(0, 0));
Matrix m = PresentationSource.FromVisual(Window.GetWindow(element)).CompositionTarget.TransformToDevice;
m.Invert();
position = m.Transform(position);
Left = position.X;
Top = position.Y;
Width = element.ActualWidth;
Height = element.ActualHeight;
}
示例11: Start
public async Task Start(string romLocation, FrameworkElement projectTo, double emulationSpeed = 1.0)
{
Window projectWindow = null;
var parent = projectTo;
while (parent.Parent != null)
{
parent = (FrameworkElement)parent.Parent;
if (parent is Window)
{
projectWindow = (Window)parent;
}
}
if (projectWindow == null)
{
throw new ArgumentException("The projection element must be a child of a window.", "projectTo");
}
using (var myProcess = Process.GetCurrentProcess())
{
foreach (var existingProcess in Process.GetProcessesByName(myProcess.ProcessName))
{
using (existingProcess)
{
if (existingProcess.Id != myProcess.Id)
{
existingProcess.Kill();
await Task.Delay(1000);
}
}
}
}
foreach (var existingProcess in Process.GetProcessesByName("bgb"))
{
using (existingProcess)
{
existingProcess.Kill();
await Task.Delay(1000);
}
}
await Task.Delay(1000);
var emulatorRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "XPlaysGameboy", "Emulator");
if (!Directory.Exists(emulatorRoot))
{
Directory.CreateDirectory(emulatorRoot);
}
var emulatorFilePath = Path.Combine(emulatorRoot, "bgb.exe");
if (!File.Exists(emulatorFilePath))
{
File.WriteAllBytes(emulatorFilePath, Resources.bgbexe);
File.WriteAllText(Path.Combine(emulatorRoot, "bgb.ini"), Resources.bgbini);
}
var information = new ProcessStartInfo(emulatorFilePath);
information.Arguments = "\"" + romLocation + "\" " +
"-setting Speed=" + emulationSpeed.ToString(new CultureInfo("en-US")) + " ";
var process = Process.Start(information);
Debug.Assert(process != null, "process != null");
while (process.MainWindowHandle == IntPtr.Zero)
{
await Task.Delay(1000);
}
await Task.Delay(1000);
var gameboyWindowHandle = NativeMethods.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Tfgb", null);
_gameboyWindowHandle = gameboyWindowHandle;
NativeMethods.ShowWindow(gameboyWindowHandle, NativeMethods.WindowShowStyle.Hide);
var style = (long)NativeMethods.GetWindowLong(process.MainWindowHandle, NativeMethods.WindowLongIndexFlags.GWL_STYLE);
style &= ~((uint)NativeMethods.SetWindowLongFlags.WS_CAPTION | (uint)NativeMethods.SetWindowLongFlags.WS_THICKFRAME | (uint)NativeMethods.SetWindowLongFlags.WS_MINIMIZE | (uint)NativeMethods.SetWindowLongFlags.WS_MAXIMIZE | (uint)NativeMethods.SetWindowLongFlags.WS_SYSMENU | (uint)NativeMethods.SetWindowLongFlags.WS_EX_APPWINDOW | (uint)NativeMethods.SetWindowLongFlags.WS_EX_OVERLAPPEDWINDOW | (uint)NativeMethods.SetWindowLongFlags.WS_OVERLAPPED | (uint)NativeMethods.SetWindowLongFlags.WS_ICONIC | (uint)NativeMethods.SetWindowLongFlags.WS_BORDER | (uint)NativeMethods.SetWindowLongFlags.WS_DLGFRAME | (uint)NativeMethods.SetWindowLongFlags.WS_EX_CLIENTEDGE | (uint)NativeMethods.SetWindowLongFlags.WS_EX_COMPOSITED | (uint)NativeMethods.SetWindowLongFlags.WS_EX_DLGMODALFRAME | (uint)NativeMethods.SetWindowLongFlags.WS_MAXIMIZE | (uint)NativeMethods.SetWindowLongFlags.WS_MAXIMIZEBOX | (uint)NativeMethods.SetWindowLongFlags.WS_MINIMIZE | (uint)NativeMethods.SetWindowLongFlags.WS_MINIMIZEBOX | (uint)NativeMethods.SetWindowLongFlags.WS_POPUP | (uint)NativeMethods.SetWindowLongFlags.WS_SIZEBOX | (uint)NativeMethods.SetWindowLongFlags.WS_TILED);
style |= (uint)NativeMethods.SetWindowLongFlags.WS_EX_TOPMOST;
style |= (uint)NativeMethods.SetWindowLongFlags.WS_EX_TOOLWINDOW;
NativeMethods.SetWindowLong(gameboyWindowHandle, NativeMethods.WindowLongIndexFlags.GWL_STYLE, (NativeMethods.SetWindowLongFlags)style);
NativeMethods.ShowWindow(gameboyWindowHandle, NativeMethods.WindowShowStyle.Show);
var resizeProjection = (Action)delegate()
{
var projectionLocation = projectTo.PointToScreen(new Point(0, 0));
var projectionSize = new Size(projectTo.ActualWidth, projectTo.ActualHeight);
NativeMethods.SetWindowPos(gameboyWindowHandle, new IntPtr(-1), (int)projectionLocation.X, (int)projectionLocation.Y,
(int)projectionSize.Width, (int)projectionSize.Height, NativeMethods.SetWindowPosFlags.SWP_NOACTIVATE);
};
projectTo.SizeChanged += delegate
{
resizeProjection();
};
projectWindow.LocationChanged += delegate
{
//.........这里部分代码省略.........
示例12: Grip_MouseLeftButtonDown
private void Grip_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
{
frameworkElement = (FrameworkElement)sender;
startDragPoint = frameworkElement.PointToScreen(Mouse.GetPosition(frameworkElement));
originalWidth = ActualWidth;
originalHeight = ActualHeight;
frameworkElement.CaptureMouse();
e.Handled = true;
}
}
示例13: GetControlWorkArea
/// <summary>
/// Returns screen workarea in witch control is placed
/// </summary>
/// <param name="control">Control</param>
/// <returns>Workarea in witch control is placed</returns>
public static Rect GetControlWorkArea(FrameworkElement control)
{
Point tabItemPos = control.PointToScreen(new Point(0, 0));
NativeMethods.Rect tabItemRect = new NativeMethods.Rect();
tabItemRect.Left = (int)tabItemPos.X;
tabItemRect.Top = (int)tabItemPos.Y;
tabItemRect.Right = (int)tabItemPos.X + (int)control.ActualWidth;
tabItemRect.Bottom = (int)tabItemPos.Y + (int)control.ActualHeight;
uint MONITOR_DEFAULTTONEAREST = 0x00000002;
System.IntPtr monitor = NativeMethods.MonitorFromRect(ref tabItemRect, MONITOR_DEFAULTTONEAREST);
if (monitor != System.IntPtr.Zero)
{
NativeMethods.MonitorInfo monitorInfo = new NativeMethods.MonitorInfo();
monitorInfo.Size = Marshal.SizeOf(monitorInfo);
NativeMethods.GetMonitorInfo(monitor, monitorInfo);
return new Rect(monitorInfo.Work.Left, monitorInfo.Work.Top, monitorInfo.Work.Right - monitorInfo.Work.Left, monitorInfo.Work.Bottom - monitorInfo.Work.Top);
}
return new Rect();
}
示例14: GetFrameworkElementWin32PixelRect
public virtual Rect GetFrameworkElementWin32PixelRect(FrameworkElement fe)
{
var feLocation = fe.PointToScreen(new Point(0, 0));
return new Rect(feLocation.X, feLocation.Y, fe.ActualWidth, fe.ActualHeight);
}
示例15: GetControlMonitor
/// <summary>
/// Returns monitor in witch control is placed
/// </summary>
/// <param name="control">Control</param>
/// <returns>Workarea in witch control is placed</returns>
public static Rect GetControlMonitor(FrameworkElement control)
{
var tabItemPos = control.PointToScreen(new Point(0, 0));
var tabItemRect = new RECT();
tabItemRect.left = (int)tabItemPos.X;
tabItemRect.top = (int)tabItemPos.Y;
tabItemRect.right = (int)tabItemPos.X + (int)control.ActualWidth;
tabItemRect.bottom = (int)tabItemPos.Y + (int)control.ActualHeight;
const uint MONITOR_DEFAULTTONEAREST = 0x00000002;
var monitor = NativeMethods.MonitorFromRect(ref tabItemRect, MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero)
{
var monitorInfo = new MONITORINFO();
monitorInfo.cbSize = Marshal.SizeOf(monitorInfo);
NativeMethods.GetMonitorInfo(monitor, monitorInfo);
return new Rect(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top);
}
return new Rect();
}