반응형
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.LocationChanged += MainWindow_LocationChanged;
        }

        private void MainWindow_LocationChanged(object? sender, EventArgs e)
        {
            Point position = btnTest.PointToScreen(new Point(0, 0));

            lblPosition.Content = $"Position From Screen ({position.X} , {position.Y})";

            Matrix matrix = PresentationSource.FromVisual(btnTest).CompositionTarget.TransformToDevice;
            double scaleX = matrix.M11;
            double scaleY = matrix.M22;
            Point finalPosition = new Point(position.X / scaleX, position.Y / scaleY);

            lblPosition2.Content = $"Sacled Position From Screen ({(int)finalPosition.X} , {(int)finalPosition.Y})";
        }
    }
반응형

+ Recent posts