【问题标题】:Use percentage to work out location based on screen resoultion in c#在c#中使用百分比根据屏幕分辨率计算位置
【发布时间】:2017-02-09 11:44:26
【问题描述】:

我在 WPF 上有两个项目我想根据屏幕分辨率和百分比计算开始 y 和结束 y。我有以下物品

文字

按钮

我想获取文本 Y,这很好

文本 X / Y 在所有 res 上的位置

1600 x 900 = x=348 y=72
1920 x 1200 = x= 348 y=72
1600 x 1200 = x=348 y=72
1400 x 1050 = x= 348 y= 72

我想用 c# 写一些东西,根据结果给我一个按钮的开始 Y 和结束 y

按钮 y 和 w/h

1600 x 900 = y-221, w=319, h=50
1920 x 1200 = y-248, w= 303, h =50
1600 x 1200 = y-248, w=319, h=50
1400 x 1050 = y-271, w=319, h=50

目前我有这些硬编码但想按百分比计算

选择以下条件为真的项目,并带有屏幕解决方案的案例陈述

x()>={0} and x()<={1} and y()>={2} and y()<={3}

【问题讨论】:

    标签: c# wpf logic


    【解决方案1】:
     Point locationFromScreen = myButton.PointToScreen(new Point(0, 0));
            PresentationSource source = PresentationSource.FromVisual(this);
            Point targetPoints = source.CompositionTarget.TransformFromDevice.Transform(locationFromScreen);
            Console.WriteLine("Top Y Coord: " + targetPoints.Y);
            Console.WriteLine("Bottom Y Coord: " + (targetPoints.Y + myButton.ActualHeight));
            Console.WriteLine("Left X Coord: " + targetPoints.X);
            Console.WriteLine("Right X Coord: " + (targetPoints.X + myButton.ActualWidth));
    

    【讨论】:

    • 让我再解释一下。所以我使用 Ranorex 和 c# 来自动化测试。
    猜你喜欢
    • 2017-04-16
    • 1970-01-01
    • 2019-11-17
    • 2012-08-31
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多