void timeDown_Tick(object sender, EventArgs e) { //HtmlDocument doc = (HtmlDocument)currentDoc; //int height = doc.Body.ScrollRectangle.Height; //current += height / 100; //if (current >= height) //{ // current = height; // timeDown.Enabled = false; // timeUp.Enabled = true; //} ////SetScrollPos(myTextBox.Handle,1,current,true); ////SendMessage(myTextBox.Handle,EM_LINESCROLL,0, //// current); //doc.Window.ScrollTo(new Point(0, current)); HTMLDocument doc = currentDoc; mshtml.IHTMLElement2 body = (mshtml.IHTMLElement2)currentDoc.body; int height = body.scrollHeight; current += height / 100; if (current <= 0) { current = 0; timeUp.Enabled = false; } //doc.Window.ScrollTo(new Point(0, current)); doc.parentWindow.scrollTo(0, current); }
public static mshtml.IHTMLElement2 GetWindowWidthAndHeight(IntPtr hwnd, mshtml.IHTMLDocument2 doc, ref int clientWidth, ref int clientHeight, ref int scrollWidth, ref int scrollHeight) { HTMLDocumentClass class2 = doc as HTMLDocumentClass; mshtml.IHTMLElement2 documentElement = null; if (class2 != null) { documentElement = class2.documentElement as mshtml.IHTMLElement2; if (documentElement != null) { clientWidth = documentElement.clientWidth; clientHeight = documentElement.clientHeight; } } else { Rect lpRect = new Rect(); documentElement = doc.body as mshtml.IHTMLElement2; WindowUtil.GetWindowRect(hwnd, out lpRect); if (documentElement != null) { clientWidth = lpRect.Right - lpRect.Left; clientHeight = lpRect.Bottom - lpRect.Top; } } if (documentElement != null) { scrollWidth = documentElement.scrollWidth; scrollHeight = documentElement.scrollHeight; } return(documentElement); }
static void Main(string[] args) { Browser browser = new IE("http://www.google.com"); IEElement banner = browser.Images[0].NativeElement as IEElement; IHTMLElement bannerHtmlElem = banner.AsHtmlElement; IEElement bodyNative = browser.Body.NativeElement as IEElement; mshtml.IHTMLElement2 bodyHtmlElem = (mshtml.IHTMLElement2)bodyNative.AsHtmlElement; mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)bodyHtmlElem.createControlRange(); controlRange.add((mshtml.IHTMLControlElement)bannerHtmlElem); controlRange.execCommand("Copy", false, System.Reflection.Missing.Value); controlRange.remove(0); if (Clipboard.GetDataObject() != null) { IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.Bitmap)) { System.Drawing.Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true); // do something here } } }
public bool needsplit(HtmlElement e) //输入节点e一定有孩子,根据节点的背景、字体等信息决定是否需要划分 { HashSet <int> setsplitNum = new HashSet <int>(); ArrayList listbc = new ArrayList(); //背景色 ArrayList listfc = new ArrayList(); //字体色 ArrayList listfs = new ArrayList(); //字体大小 ArrayList listfst = new ArrayList(); //字体信息 foreach (HtmlElement ch in e.Children) //对e中的所有直接孩子节点提取背景色等信息 { mshtml.IHTMLElement2 ch2 = (mshtml.IHTMLElement2)ch.DomElement; IHTMLCurrentStyle chstyle = ch2.currentStyle; listbc.Add(chstyle.backgroundColor); listfc.Add(chstyle.color); listfs.Add(chstyle.fontSize); listfst.Add(chstyle.fontStyle); } //如果有孩子节点的上述样式有所不同则需要分割 foreach (Object value in listbc) { if (listbc[0] != value) //如果有一个是不一样的则需要分割 { return(true); } } foreach (Object value in listfc) { if (listfc[0] != value) //如果有一个是不一样的则需要分割 { return(true); } } foreach (Object value in listfs) { if (listfs[0] != value) //如果有一个是不一样的则需要分割 { return(true); } } foreach (Object value in listfst) { if (listfst[0] != value) //如果有一个是不一样的则需要分割 { return(true); } } return(false); }
void timeUp_Tick(object sender, EventArgs e) { HTMLDocument doc = currentDoc; mshtml.IHTMLElement2 body = (mshtml.IHTMLElement2)currentDoc.body; int height = body.scrollHeight; current -= height / 100; if (current <= 0) { current = 0; timeUp.Enabled = false; } //doc.Window.ScrollTo(new Point(0, current)); doc.parentWindow.scrollTo(0, current); }
public static Rectangle GetElementRect(mshtml.IHTMLElement body, mshtml.IHTMLElement elem) { int top; int num3; int num4; int left = top = num3 = num4 = 0; mshtml.IHTMLElement2 element = elem as mshtml.IHTMLElement2; IHTMLRect o = element.getBoundingClientRect(); elem = element as mshtml.IHTMLElement; left = o.left; top = o.top; num3 = o.right - o.left; num4 = o.bottom - o.top; if (body.document != elem.document) { List <mshtml.IHTMLDOMNode> frames = new List <mshtml.IHTMLDOMNode>(); GetEleParentFrames(body as mshtml.IHTMLDOMNode, elem as mshtml.IHTMLDOMNode, frames); foreach (mshtml.IHTMLDOMNode node in frames) { IHTMLRect rect2 = (node as mshtml.IHTMLElement2).getBoundingClientRect(); left += rect2.left; top += rect2.top; } } Rectangle rectangle = new Rectangle { X = left, Y = top, Width = num3, Height = num4 }; if (o != null) { Marshal.ReleaseComObject(o); } return(rectangle); }
/// <summary> /// 웹에 이미지를 폴더에 저장한다. /// </summary> /// <param name="FolderPath"></param> public void AllImage_Save(string FolderPath) { string strElName; mshtml.IHTMLElement2 body2 = (mshtml.IHTMLElement2)HTMLDoc.body; mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)body2.createControlRange(); IHTMLElementCollection imgs = HTMLDoc.images; foreach (mshtml.HTMLImg objImg in imgs) { controlRange.add((mshtml.IHTMLControlElement)objImg); controlRange.execCommand("Copy", false, System.Reflection.Missing.Value); controlRange.remove(0); strElName = objImg.nameProp; if (Clipboard.GetDataObject() != null) { IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.Bitmap)) { Image image = (Image)data.GetData(DataFormats.Bitmap, true); if (strElName.Substring(strElName.IndexOf(".") + 1).ToLower() == "jpg") { image.Save(FolderPath + strElName, System.Drawing.Imaging.ImageFormat.Jpeg); } else if (strElName.Substring(strElName.IndexOf(".") + 1).ToLower() == "gif") { image.Save(FolderPath + strElName, System.Drawing.Imaging.ImageFormat.Gif); } else if (strElName.Substring(strElName.IndexOf(".") + 1).ToLower() == "png") { image.Save(FolderPath + strElName, System.Drawing.Imaging.ImageFormat.Png); } } } } }
/// <summary> /// 이미지 이름으로 찾는다. /// </summary> /// <param name="imgName">이미지파일명이나 herf 경로</param> /// <returns></returns> public Image Image_Get(string imgName) { string strElName; mshtml.IHTMLElement2 body2 = (mshtml.IHTMLElement2)HTMLDoc.body; mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)body2.createControlRange(); IHTMLElementCollection imgs = HTMLDoc.images; Image image = null; foreach (mshtml.HTMLImg objImg in imgs) { if (objImg.nameProp != imgName && objImg.href != imgName) { continue; } controlRange.add((mshtml.IHTMLControlElement)objImg); controlRange.execCommand("Copy", false, System.Reflection.Missing.Value); controlRange.remove(0); strElName = objImg.nameProp; if (Clipboard.GetDataObject() != null) { IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.Bitmap)) { image = (Image)data.GetData(DataFormats.Bitmap, true); } } } return(image); }
public static IHTMLRect GetLocation(HtmlElement he) { mshtml.IHTMLElement2 domElement = (mshtml.IHTMLElement2)he.DomElement; return(domElement.getBoundingClientRect()); }