2017-02-09 3 views
-1

私はWPF上に2つのアイテムを持っています私は、スクリーンresoultionとパーセンテージに基づいて開始yと終了yを計算したいと思います。私は持っている以下の項目%でスクリーンresoultionに基づいて場所を解決するために%を使用する#

テキスト

ボタン

私はすべてが

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 

Iをresは上

テキストX/Y位置微であるテキストYを取得したいと思いますC#で何かを書いて、resoultionに基づいてボタンの開始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 

現在、私は、これらのハードコードされているが、割合で計算したい

以下の条件が画面resoultionsのためのcase文で真である

選択項目

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

答えて

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

もう少し説明しましょう。だから私はテストを自動化するためにC#でRanorexを使用しています。 – user2968227

関連する問題