0
A
回答
1
此功能在DotNetBrowser DOM API中不存在。但是可以使用Javascript來解決這種情況。
更新:DotNetBrowser 1.8.3中增加了此功能。現在可以通過DOM API obtain absolute or relative DOMElement position。
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,這個解決方案似乎有效,但並非每次都有效。 –
相關問題
- 1. 如何獲取表中某個特定元素的座標r
- 2. 如何用絕對位置獲取元素的絕對座標(JavaScript,瀏覽器)
- 3. firebug - 獲取絕對座標
- 4. 如何獲取絕對定位元素相對於另一個元素的放置座標?
- 5. 獲取元素的座標
- 6. 在DynamicReports中,如何設置報表元素的絕對座標
- 7. 如何在iOS上的Safari中獲取絕對座標?
- 8. 如何通過javascript獲取元素在特定座標處的ID
- 9. WPF TouchDevice獲取絕對座標
- 10. 獲取特定元素的對象
- 11. 獲取jQuery元素數組的座標
- 12. 獲取`img`元素的XY座標
- 13. Applescript - 獲取元素的座標
- 14. 獲取DOM元素的屏幕座標
- 15. 如何根據文檔獲取SVG中元素的座標?
- 16. 如何在IE8中獲取元素的樣式座標
- 17. 如何獲取BHO中網頁元素的屏幕座標
- 18. 如何獲取網頁中元素的x,y座標?
- 19. 如何從jquery的父元素中獲取子元素的xy座標?
- 20. Angular JS:如何獲取與$ scope中的對象關聯的元素的座標
- 21. 從ClassName獲取的所有元素中獲取特定元素?
- 22. 如何獲取特定元素
- 23. 在觸摸座標獲取UI元素
- 24. 通過座標獲取元素?
- 25. 如何獲取觸摸事件點相對於目標元素的x座標?
- 26. 如何點擊一個元素的特定座標
- 27. 如何從座標列表中獲取元素
- 28. 如何獲取特定元素之前的類的元素數
- 29. 如何獲取列表中所有元素的絕對值?
- 30. 如何獲取特定div內的光標座標?
這是不夠的,知道的相對或絕對相對於視,但對整個屏幕(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