2016-11-13 9 views

答えて

1

この機能は、まだDotNetBrowser DOM APIには存在しません。しかし、Javascriptを使用してこのケースを回避することは可能です。

更新:この機能はDotNetBrowser 1.8.3で追加されました。 DOM APIを使用してobtain absolute or relative DOMElement positionにアクセスできるようになりました。

+0

それは(ピクセルをincluingビューポートが、画面全体に相対または絶対相対を知るには十分ではありません解決)。 Internet Explorerでは、DOMにトランスフォーメーションサービスがあり、DotNetBrowserに相当するものがあります。 var rect = el2.getBoundingClientRect(); var displayServices = el.document as IDisplayServices; var point =新しいtagPOINT {x = rect.left、y = rect.top}; displayServices.TransformPoint(参照ポイント、_COORD_SYSTEM.COORD_SYSTEM_FRAME、 _COORD_SYSTEM.COORD_SYSTEM_GLOBAL、el); – Paulo

0

ウィンドウ、ビューポート、および要素の絶対座標を組み合わせることができます。あなたがここにScreen.PrimaryScreen.Bounds財産

を使用することができ、画面の解像度を取得するに は、コードサンプルです:

public partial class Form1 : Form 
{ 
    BrowserView browserView; 

    public Form1() 
    { 
     InitializeComponent(); 
     browserView = new WinFormsBrowserView(); 

     browserView.Browser.FinishLoadingFrameEvent += Browser_FinishLoadingFrameEvent; 
     Controls.Add((Control)browserView); 
     browserView.Browser.LoadURL("google.com"); 
    } 

    private void Browser_FinishLoadingFrameEvent(object sender, DotNetBrowser.Events.FinishLoadingEventArgs e) 
    { 
     if (e.IsMainFrame) 
     { 
      DOMDocument document = e.Browser.GetDocument(); 
      DOMElement element = document.GetElementByName("btnK"); 
      Rectangle rectangle = element.BoundingClientRect; 

      Rectangle resolution = Screen.PrimaryScreen.Bounds; 
      Debug.WriteLine("Screen resolution = " + resolution.Width + 
       'x' + resolution.Height); 

      Debug.WriteLine("Form X = " + Location.X); 
      Debug.WriteLine("Form Y = " + Location.Y); 
      Debug.WriteLine("browserView X = " + ((Control)browserView).Location.X); 
      Debug.WriteLine("browserView Y = " + ((Control)browserView).Location.Y); 
      Debug.WriteLine("X = " + rectangle.Location.X); 
      Debug.WriteLine("Y = " + rectangle.Location.Y); 

      int absoluteX = Location.X + 
       ((Control)browserView).Location.X + rectangle.Location.X; 
      int absoluteY = Location.Y + 
       ((Control)browserView).Location.Y + rectangle.Location.Y; 

      Debug.WriteLine("Absolute X = " + absoluteX); 
      Debug.WriteLine("Absolute Y = " + absoluteY); 
     } 
    } 
} 
+0

このソリューションはうまくいくようですが、毎回ではありません。 –

関連する問題