使用百分比根据c#

时间:2017-02-09 11:44:27

标签: c# wpf logic

我在WPF上有两个项目我想根据屏幕重新设置和百分比来计算开始y和结束y。我有以下项目

文本

按钮

我想获得正确的文字Y

所有res上的文字X / Y位置

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并根据resoultion结束按钮

按钮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}

1 个答案:

答案 0 :(得分:0)

 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));