2016-11-13 80 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,这个解决方案似乎有效,但并非每次都有效。 –