WPF: Converting between screen coordinates and WPF coordinates

后端 未结 2 1838
孤独总比滥情好
孤独总比滥情好 2020-12-29 09:26

I understand that WPF coordinates are different from \"real\" screen coodinates (pixel coordinates) if the computer is not using the default DPI setting. In my program I wan

2条回答
  •  醉酒成梦
    2020-12-29 10:08

    Does this work if you place it in the code-behind for your Window?

    protected override void OnContentRendered(System.EventArgs e)
    {
        base.OnContentRendered(e);
        MoveToLowerRightCorner();
    }
    
    private void MoveToLowerRightCorner()
    {
        var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
        var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
        var corner = transform.Transform(new Point(workingArea.Right, workingArea.Bottom));
        this.Left = corner.X - this.ActualWidth;
        this.Top = corner.Y - this.ActualHeight;
    }
    

提交回复
热议问题