好的,請考慮這張圖片。
I develop an IE extension in c# and I would :
- the distance in red, between top of screen and top of `visible webpage`
- the distance in red between left of screen and left of `visible webpage`
- the width/heigth of the visible webpage
當然,考慮到我有整個屏幕的大小。如果我有紅色和黑色,我可以計算綠色。
什麼意思?我有千屏幕座標(X,Y),我必須計算相對於網頁的座標。
Example :
Considering
Screen size : 1200 * 800
Webpage size : 400*300
Red distance between left screen border and left webpage border : 200
Red distance between top screen border and top webpage border : 300
So my coordinates screen => relative webpage becomes :
(100, 100) => OUTSIDE WEBPAGE(ignored)
(1100, 650) => OUTSIDE WEBPAGE (ignored)
(200, 300) => (0,0)
(250, 400) => (50, 100)
其實我有這樣的代碼,this
從AddinExpress.IE.ADXIEModule
繼承,thetoolbarObj是我加入到InternetExplorer的工具欄。所以我可以在它上面使用pointToScreen,而且我並不需要它,但工具欄的左下角並不是我所需要的,我需要網頁的左邊角。
public void getUtilsDimension()
{
Rectangle resolution = Screen.PrimaryScreen.Bounds;
Int32 screenWidth = resolution.Width;
Int32 screenHeight = resolution.Height;
AddinExpress.IE.ADXIEToolBarItem toolbarItem = this.ToolBars[0];
AddinExpress.IE.ADXIEToolbar toolbarObj = toolbarItem.ToolBarObj;
Point leftCornerWebPage = toolbarObj.PointToScreen(new Point(0, 0));
Int32 toolbarHeight = toolbarObj.Height;
Int32 toolbarWidth = toolbarObj.Width;
Debug.WriteLine("Largeur écran : " + screenWidth);
Debug.WriteLine("Hauteur écran : " + screenHeight);
Debug.WriteLine("LeftCornerX : " + leftCornerWebPage.X);
Debug.WriteLine("LeftCornerY : " + leftCornerWebPage.Y);
Debug.WriteLine("toolbarHeight : " + toolbarHeight);
Debug.WriteLine("toolbarWidth : " + toolbarWidth);
}
這是我所得到的實際,屏幕爲1600 * 900,pointToScreen返回紅十字會(484158)的座標。但我需要將藍色十字的座標作爲可見網頁的寬度和高度。我知道我可以通過$(window)在Jquery中獲得,但我不知道如何與C#。
我可以在HTLMDocument(typeof mshtml.HTMLDocument
)和this.HTMLDocument
上訪問,不幸的是pointToScreen在HTMLDocument對象上不可用。
編輯:IT方面的第一張截圖,但當然鉻,應該是IE
更新08/12
OK我有可見的網頁的寬度和高度(我的屏幕截圖上的黑色線條) 唯一缺失的是我截圖上的藍色十字的座標2
var heightVisibleWebPage = HTMLDocument.documentElement.offsetHeight;
var widthVisibleWebPage = HTMLDocument.documentElement.offsetWidth;
對於賞金,我需要藍十字的確切座標。不管怎樣。無論Internet Explorer版本,收藏夾/工具/命令/狀態欄是否顯示,它都可以工作。
更新08/12 HTMLDocument的
HTMLDocument
是AddinExpress,它不是一個System.Windows.Forms.HtmlDocument
public mshtml.HTMLDocument HTMLDocument
{
get
{
return (this.HTMLDocumentObj as mshtml.HTMLDocument);
}
}
他的父母HTMLDocument的。parentWindows是IHTMLWindow2對象
HTMLDocumentObj是
public class ADXIEModule : Component, IRemoteModule2, IRemoteModule, IObjectWithSite, IWin32Window
{
...
//
// Résumé :
// Gets the automation object (a COM object) of the active document, if any.
//
// Notes :
// When the active document is an HTML page, this property provides access to
// the contents of the HTML Document Object Model (DOM). Specifically, it returns
// an HTMLDocument object reference. The HTMLDocument object is functionally
// equivalent to the HTML document object used in HTML page script. It supports
// all the properties and methods necessary to access the entire contents of
// the active HTML document.
// The HTMLDocument object can be used through the IHTMLDocument interface,
// the IHTMLDocument2 interface, and the IHTMLDocument3 interface.
// When other document types are active, such as a Microsoft Word document,
// this property returns the document automation object of that document. For
// Word documents, this is the Document object.
[Browsable(false)]
public object HTMLDocumentObj { get; }
...
}
成員解釋時-1爲界,請;)
downvote可能是因爲您沒有顯示您嘗試過的內容。這裏的用戶在這裏幫助解決您的代碼問題,而不是爲您編寫解決方案。你有代碼顯示嗎? – 2014-12-01 17:47:27
好的,它的編輯 – amdev 2014-12-02 11:54:04
HTMLDocument應該有parentWindow字段 - 它是否返回整個IE窗口或html繪圖矩形的容器? – Gerino 2014-12-08 17:22:25