2016-11-13 57 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 = new tagPOINT {x = rect.left,y = rect.top}; displayServices.TransformPoint(ref point,_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

Strage,這個解決方案似乎有效,但並非每次都有效。 –

相關問題