Ejemplo n.º 1
0
        //取得驗證碼圖片
        public Image GetRegCodePic(WebBrowser WB, String ImgName, String Src, String Id)
        {
            HTMLDocument        doc  = WB.Document.DomDocument as HTMLDocument;
            HTMLBody            body = doc.body as HTMLBody;
            IHTMLControlRange   rang = body.createControlRange() as IHTMLControlRange;
            IHTMLControlElement Img;

            if (ImgName == "")
            {
                //如果沒有圖片的名字,通過Src或Alt中的關鍵字來取
                Int32 ImgNum = GetPicIndex(WB, Src, Id);
                if (ImgNum == -1)
                {
                    return(null);
                }
                Img = WB.Document.Images[ImgNum].DomElement as IHTMLControlElement;
            }
            else
            {
                Img = WB.Document.All[ImgName].DomElement as IHTMLControlElement;
            }
            rang.add(Img);
            rang.execCommand("copy", false, Type.Missing);
            Image RegImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(RegImg);
        }
Ejemplo n.º 2
0
        private async Task <ImageSource> GetVerifyCodeInternal()
        {
            //await HookScript(WebBrowser, "/Assets/Json.js");
            //await HookScript(WebBrowser, "/Assets/GetCode.js");
            //var resultData = WebBrowser.Document.InvokeScript("GetCode");

            //var result = JsonConvert.DeserializeObject<ImageSize>(resultData.ToString());

            //if (result.ErrorCode != ErrorCode.Ok)
            //{
            //    throw new Exception($"{result.ErrorCode}");
            //}


            foreach (HtmlElement image in WebBrowser.Document.Images)
            {
                var dom = (IHTMLImgElement)image.DomElement;
                if (dom.src == "http://www.tsdm.net/plugin.php?id=oracle:verify")
                {
                    HTMLBody          body = (HTMLBody)WebBrowser.Document.Body.DomElement;
                    IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
                    rang.add((IHTMLControlElement)dom);
                    var result = rang.execCommand("Copy");

                    await Task.Delay(1000);

                    Bitmap bitmap = (Bitmap)System.Windows.Forms.Clipboard.GetImage();
                    var    s      = BitmapToBitmapSource(bitmap);
                    return(s);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取WebBrowser指定的图片
        /// </summary>
        /// <param name="webBrowser">需要获取图片的WebBrowser</param>
        /// <param name="imgID">指定的图片的id(优先查找指定id)</param>
        /// <param name="imgSrc">指定的图片的src,支持模糊查询</param>
        /// <param name="imgAlt">指定的图片的src, 支持模糊查询</param>
        /// <returns></returns>
        public static Image GetRegCodePic(ref WebBrowser webBrowser, String imgID, String imgSrc, String imgAlt)
        {
            HTMLDocument        doc  = (HTMLDocument)webBrowser.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img;

            // 如果没有图片的ID,通过Src或Alt中的关键字来取
            if (imgID.Length == 0)
            {
                Int32 ImgNum = GetPicIndex(ref webBrowser, ref imgSrc, ref imgAlt);

                if (ImgNum == -1)
                {
                    return(null);
                }

                img = (IHTMLControlElement)webBrowser.Document.Images[ImgNum].DomElement;
            }
            else
            {
                img = (IHTMLControlElement)webBrowser.Document.All[imgID].DomElement;
            }

            rang.add(img);
            rang.execCommand("Copy", false, null);
            Image regImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(regImg);
        }
Ejemplo n.º 4
0
        private Image GetCheckImage(HtmlElement ImageTag)
        {
            HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;

            HTMLBody body = (HTMLBody)doc.body;

            IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();

            IHTMLControlElement Img = (IHTMLControlElement)ImageTag.DomElement; //圖片地址

            bool containImg  = Clipboard.ContainsImage();
            bool containText = Clipboard.ContainsText();

            Image  oldImage = Clipboard.GetImage();
            string oldText  = Clipboard.GetText();

            rang.add(Img);

            rang.execCommand("Copy", false, null); //拷貝到內存

            Image numImage = Clipboard.GetImage(); //從Clipboard中取圖

            if (containImg)
            {
                try { Clipboard.SetImage(oldImage); } //還原
                catch { }
            }
            else if (containText)
            {
                try { Clipboard.SetText(oldText); } //還原
                catch { }
            }

            return(numImage);
        }
Ejemplo n.º 5
0
        private Image GetWebImage(HTMLDocument doc, IHTMLControlElement ImgeTag)
        {
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = ImgeTag; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            try
            {
                if (oldImage != null)
                {
                    Clipboard.SetImage(oldImage);
                }
            }
            catch (Exception ex)
            {
                // MessageBox.Show("GetWebImage:" + ex.Message);
            }

            return(numImage);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="WebCtl">WebBrowser控件</param>
        /// <param name="ImgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        public static Image GetWebImage(Form1 form, WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            Image image = null;

            form.Invoke((EventHandler)(delegate
            {
                // 这里写你的控件代码,比如
                HTMLDocument doc = (HTMLDocument)WebCtl.Document.DomDocument;
                HTMLBody body = (HTMLBody)doc.body;
                IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
                IHTMLControlElement Img = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

                Image oldImage = Clipboard.GetImage();
                rang.add(Img);
                rang.execCommand("Copy", false, null);  //拷贝到内存
                image = Clipboard.GetImage();
                try
                {
                    Clipboard.SetImage(oldImage);
                }
                catch
                {
                }
            }
                                       ));

            return(image);
        }
        /*
         *
         *  示例1:
         *  下面是某个站的注册码图片的HTML部分源代码
         *  <IMG height=80 alt="Registration Verification Code" src="......" width=290 border=0>
         *  picturebox1.Image =GetRegCodePic(wbMail, "", "", "Registration Verification Code")
         *
         *  示例2:
         *  下面是某个站的注册码图片的HTML部分源代码
         *  <IMG id=CAPTCHAImage src="......." name=CAPTCHAImage>
         *  picturebox1.Image =GetRegCodePic(wbMail, "CAPTCHAImage", "", "")  //通过验证码Html元素的名字来
         *
         */
        #endregion

        /// <summary>
        /// 获取验证码图片
        /// </summary>
        /// <param name="wbMail"></param>
        /// <param name="ImgName"></param>
        /// <param name="Src"></param>
        /// <param name="Alt"></param>
        /// <returns></returns>
        public static Image GetRegCodePic(WebBrowser wbMail, string ImgName, string Src, string Alt)
        {
            HTMLDocument        doc  = (HTMLDocument)wbMail.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img;

            if (ImgName == "") //如果没有图片的名字,通过Src或Alt中的关键字来取
            {
                int ImgNum = GetPicIndex(wbMail, Src, Alt);
                if (ImgNum == -1)
                {
                    return(null);
                }
                Img = (IHTMLControlElement)wbMail.Document.Images[ImgNum].DomElement;
            }
            else
            {
                Img = (IHTMLControlElement)wbMail.Document.All[ImgName].DomElement;
            }
            rang.add(Img);
            rang.execCommand("Copy", false, null);
            Image RegImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(RegImg);
        }
Ejemplo n.º 8
0
        public override IPDFComponent GetComponent(IHtmlContentParser parser, string name, out HtmlComponentType type)
        {
            type = HtmlComponentType.Body;
            HTMLBody body = new HTMLBody();

            body.ID = "html-body";
            return(body);
        }
Ejemplo n.º 9
0
        protected override void Execute(CodeActivityContext context)
        {
            Microsoft.Office.Interop.Outlook.Application outlookApplication = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.MailItem    email = (Microsoft.Office.Interop.Outlook.MailItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            var    to       = To.Get(context);
            var    cc       = CC.Get(context);
            var    bcc      = BCC.Get(context);
            var    subject  = Subject.Get(context);
            string body     = (Body != null ?Body.Get(context) : null);
            string htmlbody = (HTMLBody != null ? HTMLBody.Get(context) : null);

            if (!string.IsNullOrEmpty(htmlbody))
            {
                body = htmlbody;
            }
            var attachments = Attachments.Get(context);
            var uiaction    = UIAction.Get(context);

            email.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;
            email.To         = to;
            email.Subject    = subject;
            email.HTMLBody   = body;
            email.CC         = cc;
            email.BCC        = bcc;

            if (attachments != null && attachments.Count() > 0)
            {
                foreach (var attachment in attachments)
                {
                    if (!string.IsNullOrEmpty(attachment))
                    {
                        email.Attachments.Add(attachment, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 100000, Type.Missing);
                    }
                }
            }
            if (uiaction == "Show")
            {
                email.Display(true);
            }
            //else if(uiaction == "SendVisable")
            //{
            //    email.Display(true);
            //    email.Send();
            //}
            else
            {
                email.Send();
            }
            if (EMail != null)
            {
                EMail.Set(context, new email(email));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// For each page that the browser loads, we look for one that fulfills all the following criteria:
        ///  - Has a meta-element named "Application-State" (that should consist of a ";"-separated list of "key=val" pairs)
        ///  - The content of the application-state contains "service=IDP" to tell that the response is coming from the identity provider (IDP)
        ///  - The content of the application-state contains "authenticated=true" to tell that the authentication went well
        ///  - The content of the application-state contains "state=token" to signal that the reponse contains the SAML token response
        /// If the above is true, the response contains the SAML token response as an attribute on the BODY tag named SSO_SAML2_TOKEN.
        /// </summary>
        private void OnLoadCompleted(object sender, NavigationEventArgs args)
        {
            Console.WriteLine("OnLoadCompleted: {0}", args.Uri);
            try
            {
                HTMLDocumentClass dom = (HTMLDocumentClass)(_browser.Document);

                // First, look for the application-state meta element
                IHTMLElementCollection applicationStateElementCollection = dom.getElementsByName("Application-State");

                // If there is no application-state, it is not the right page
                if (applicationStateElementCollection.length < 1)
                {
                    return;
                }

                // Application state looks like this: <meta name="Application-State" content="service=IDP;federated=False;env=Test;state=Ok;authenticated=True;">
                string applicationState = ((HTMLMetaElement)applicationStateElementCollection.item(0)).content;

                // Split at ";" sepearator
                string[] applicationStateElements = applicationState.Split(';');

                // Look for the "state=idp" - this means that the process is finished
                // Without checking this, we don't know whether the authentication failed or just haven't gotten there yet
                if (!applicationStateElements.Any(s => (s.Equals("service=idp", StringComparison.OrdinalIgnoreCase))))
                {
                    // This is not the IDP responding, probably a page earlier in the login flow - just skip it
                    return;
                }

                // This is the IDP response page. Check if the list of values contains authenticated=true
                if (applicationStateElements.Any(s => (s.Equals("authenticated=true", StringComparison.OrdinalIgnoreCase))) &&
                    applicationStateElements.Any(s => (s.Equals("state=token", StringComparison.OrdinalIgnoreCase))))
                {
                    // On the final page, the SAML-Response is on an attribute on the body element, named SSO_SAML2_TOKEN
                    HTMLBody bodyElement = ((HTMLBody)dom.getElementsByTagName("body").item(0));
                    object   attribute   = bodyElement.getAttribute("SSO_SAML2_TOKEN");

                    SAMLResponse = attribute.ToString();
                    DialogResult = true;
                }
                else
                {
                    DialogResult = false;
                }
                Close();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                Close();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取验证码图片
        /// </summary>
        /// <param name="imgId"></param>
        /// <returns></returns>
        private Image GetValidateCode(string imgId)
        {
            Image               myImage = new Bitmap(60, 20);
            HtmlDocument        doc     = webBrowser1.Document;
            IHTMLControlElement img     = (IHTMLControlElement)doc.Images[imgId].DomElement;
            IHTMLDocument2      tmpDoc  = webBrowser1.Document.DomDocument as IHTMLDocument2;
            HTMLBody            body    = (HTMLBody)tmpDoc.body;
            IHTMLControlRange   rang    = (IHTMLControlRange)body.createControlRange();

            rang.add(img);
            rang.execCommand("Copy", false, null);
            myImage = Clipboard.GetImage();
            return(myImage);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取图像内容
        /// </summary>
        /// <param name="browser">显示图像的浏览器控件</param>
        /// <param name="imgElement">从浏览器中读取到的img</param>
        private static Image GetImage(WebBrowser browser, HtmlElement imgElement)
        {
            HTMLDocument        doc  = (HTMLDocument)browser.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img  = (IHTMLControlElement)(imgElement.DomElement);

            rang.add(img);
            rang.execCommand("Copy", false, null);
            Image regImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(regImg);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="webCtl">WebBrowser控件</param>
        /// <param name="imgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        private Image GetWebImage(WebBrowser webBrowser, string imgeTagId)
        {
            System.Windows.Forms.HtmlDocument winHtmlDoc = webBrowser.Document;
            HTMLDocument        doc    = (HTMLDocument)winHtmlDoc.DomDocument;
            HtmlElement         imgTag = winHtmlDoc.GetElementById(imgeTagId);
            HTMLBody            body   = (HTMLBody)doc.body;
            IHTMLControlRange   rang   = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement imgE   = (IHTMLControlElement)imgTag.DomElement; //图片地址

            rang.add(imgE);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            return(numImage);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="WebCtl">WebBrowser控件</param>
        /// <param name="ImgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        private Image GetWebImage(WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            HTMLDocument        doc  = (HTMLDocument)WebCtl.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            Clipboard.SetImage(oldImage);
            return(numImage);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 得到验证码图片
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="ImgName"></param>
        /// <returns></returns>
        public static Image GetPic(HtmlDocument doc, string ImgName)
        {
            Image        RegImg;
            HTMLDocument domDoc = (HTMLDocument)doc.DomDocument;

            HTMLBody            body = (HTMLBody)domDoc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img;


            Img = (IHTMLControlElement)doc.All[ImgName].DomElement;

            rang.add(Img);
            rang.execCommand("Copy", false, null);
            RegImg = Clipboard.GetImage();
            Clipboard.Clear(); return(RegImg);
        }
Ejemplo n.º 16
0
        public void GetCacheImage(WebBrowser webBrower, string id, MyDelegate myDelegate, Window window)
        {
            HTMLDocument doc  = (HTMLDocument)webBrower.Document;
            HTMLBody     body = (HTMLBody)doc.body;

            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img  = (IHTMLControlElement)(doc.getElementById(id));

            rang.add(img);
            rang.execCommand("Copy", true, null);
            try
            {
                BitmapSource bitmap = Clipboard.GetImage();
                byte[]       dcimg  = ConvertToBytes(bitmap);//验证码字节码
                Clipboard.Clear();
                string result           = Dc.RecByte_A(dcimg, dcimg.Length, ConfigurationManager.AppSettings["chaorenuser"], ConfigurationManager.AppSettings["chaorenpw"], ConfigurationManager.AppSettings["softid"]);
                string verificationCode = result.Substring(0, result.IndexOf("|!|"));
                myDelegate(verificationCode);
                doc  = null;
                body = null;
                rang = null;
                img  = null;
                GC.Collect();
            }
            catch (Exception e)
            {
                Thread thr = new Thread(() =>
                {
                    string userSaveFiler = Directory.GetCurrentDirectory() + "\\weeorlog.txt";//用户账号保存文件
                    FileStream fs        = new FileStream(userSaveFiler, FileMode.OpenOrCreate);
                    StreamWriter sw      = new StreamWriter(fs);
                    sw.WriteLine(e.ToString());
                    sw.Close();
                    fs.Close();
                    //这里还可以处理些比较耗时的事情。
                    Thread.Sleep(1000);//延时2秒
                    window.Dispatcher.Invoke(new Action(() =>
                    {
                        Clipboard.Clear();
                        GetCacheImage(webBrower, id, myDelegate, window);
                    }));
                });
                thr.Start();
            }
        }
Ejemplo n.º 17
0
        private void Browser_LoadCompleted(NavigationEventArgs e)
        {
            IHTMLDocument2   doc  = (IHTMLDocument2)Browser.Document;
            IHTMLBodyElement body = (IHTMLBodyElement)doc.body;

            doc.charset = "utf-8";
            ((IHTMLElement3)body).contentEditable = "true";
            _body = (HTMLBody)doc.body;

            dynamic d = doc;

            d.attachEvent("onkeyup", _listener);
            d.attachEvent("onblur", _listener);
            d.attachEvent("onchange", _listener);
            d.attachEvent("oninput", _listener);
            d.attachEvent("onpaste", _listener);
            d.attachEvent("oncut", _listener);
        }
Ejemplo n.º 18
0
        //讀入驗證碼
        private Image Getimage()
        {
            HTMLDocument      doc   = webBrowser1.Document.DomDocument as HTMLDocument;
            HTMLBody          body  = doc.body as HTMLBody;
            IHTMLControlRange range = body.createControlRange();
            //取得網頁中第[0]個圖片(因為我要取得的圖片的沒有ID)
            //也可使用GetElementById("ID名稱")取得圖片
            IHTMLControlElement imgElement =
                webBrowser1.Document.GetElementsByTagName("img")[0].DomElement as IHTMLControlElement;

            //複製圖片至剪貼簿
            range.add(imgElement);
            range.execCommand("copy", false, Type.Missing);
            //取得圖片
            img = Clipboard.GetImage();
            Clipboard.Clear();
            return(img);
        }
Ejemplo n.º 19
0
        public Image GetWebImage(HTMLBody body, HtmlElement ImageTag)
        {
            IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img = (IHTMLControlElement)ImageTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();
            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();
            try
            {
                Clipboard.SetImage(oldImage);
            }
            catch
            {
            }

            return numImage;
        }
        public static Image GetRegCodePic(WebBrowser wb, HtmlElement ImgeTag)
        {
            if (ImgeTag.TagName.ToUpper() != "IMG")
            {
                return(null);
            }
            HTMLDocument        doc  = (HTMLDocument)wb.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            Clipboard.Clear();
            return(numImage);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 获取页面验证码图片转换为字符串
        /// </summary>
        /// <param name="webbrowser"></param>
        /// <returns></returns>
        public string ConImageCodeToString(System.Windows.Forms.WebBrowser webbrowser, out HtmlElement imagecodeelement)
        {
            string imagecode = default(string);

            try
            {
                #region  解析验证码
                HtmlElementCollection imageresult = webbrowser.Document.Images;
                imagecodeelement = null;
                foreach (var item in imageresult)
                {
                    HtmlElement curimg = item as HtmlElement;
                    if (curimg.OuterHtml.Contains("rand_code.csp"))
                    {
                        /*获取页面图片*/
                        imagecodeelement = curimg;
                        HTMLDocument        hdoc  = (HTMLDocument)webbrowser.Document.DomDocument;
                        HTMLBody            hbody = (HTMLBody)hdoc.body;
                        IHTMLControlRange   hcr   = (IHTMLControlRange)hbody.createControlRange();
                        IHTMLControlElement hImg  = (IHTMLControlElement)curimg.DomElement;
                        hcr.add(hImg);
                        hcr.execCommand("Copy", false, null);
                        Image  CodeImage = Clipboard.GetImage();
                        Bitmap bitmap    = new Bitmap(CodeImage);
                        /*******解析验证码********/
                        BreakCodeServer unCheckobj = new BreakCodeServer(bitmap);
                        Thread.Sleep(2000);
                        imagecode = unCheckobj.getPicnum();
                        break;
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                SetText(System.DateTime.Now.ToString() + "\r\n解析验证码失败\r\n");
                imagecodeelement = null;
                imagecode        = "";
            }
            return(imagecode);
        }
Ejemplo n.º 22
0
        private System.Drawing.Image GetWebImage(System.Windows.Forms.WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            HTMLDocument        doc  = (HTMLDocument)WebCtl.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            var oldImage = System.Windows.Forms.Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            var numImage = System.Windows.Forms.Clipboard.GetImage();

            try
            {
                System.Windows.Forms.Clipboard.SetImage(oldImage);
            }
            catch
            {
            }

            return(numImage);
        }
Ejemplo n.º 23
0
        public string getVimg(HtmlDocument document, string vimgID)
        {
            HtmlElement         vimg = document.GetElementById(vimgID);
            HTMLDocument        doc  = (HTMLDocument)document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img  = (IHTMLControlElement)vimg.DomElement;

            try
            {
                Image oldImage = Clipboard.GetImage();
                rang.add(img);
                rang.execCommand("Copy", false, null);
                Image numImage = Clipboard.GetImage();
                Clipboard.SetImage(oldImage);
                using (Page page = engine.Process(new Bitmap(numImage)))
                {
                    return(page.GetText());
                }
            }catch (Exception ex)
            {
                return("");
            }
        }
Ejemplo n.º 24
0
        public override object getVerCodeImage(HtmlDocument indoc)
        {
            HTMLDocument doc = (HTMLDocument)indoc.DomDocument;

            if (doc == null)
            {
                return(doc);
            }
            //Image img = null;
            HtmlElement ImgeTag = indoc.GetElementById("img-valcode");

            //mshtml.IHTMLElementCollection
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址
            object oldobj            = Clipboard.GetDataObject();               //备份粘贴版数据

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            rang = null;
            return(numImage);
        }
Ejemplo n.º 25
0
        public static Image GetWebImage_test(WebBrowser WebCtl, string doucmentName)
        {
            HtmlElement         ImgeTag = WebCtl.Document.All[doucmentName];
            HTMLDocument        doc     = (HTMLDocument)WebCtl.Document.DomDocument;
            HTMLBody            body    = (HTMLBody)doc.body;
            IHTMLControlRange   rang    = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img     = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            try
            {
                Clipboard.SetImage(oldImage);
            }
            catch
            {
            }

            return(numImage);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// ポップアップを表示します
        /// </summary>
        /// <param name="html">表示するHTML</param>
        public void Show(string html)
        {
            HTMLDocument hd   = iectv.DomDocument;
            HTMLBody     body = (HTMLBody)hd.body;
            IHTMLElement root = hd.getElementById("popupBase");

            // ポップアップのルートが作成されていなければ
            if (root == null)
            {
                // ポップアップの基本となる要素を挿入
                body.insertAdjacentHTML("afterBegin", "<dl><div id=\"popupBase\" style=\"" + fontHtml + "\"></div></dl>");
                root = hd.getElementById("popupBase");
            }

            // ポップアップ元を作成
            root.insertAdjacentHTML("beforeEnd",
                                    String.Format("<div id=\"p{0}\" style=\"border: solid gray 1px; padding: 3px; background: window; overflow: auto; position: absolute;\"></div>", childCount));

            // 表示内容を設定
            IHTMLElement div = hd.getElementById("p" + childCount);

            div.innerHTML = html;


            // ポップアップの最大幅を求める
            int maxWidth  = body.clientWidth;
            int maxHeight = body.clientHeight / 2 + body.clientHeight / 3; // 画面の3/2

            // 要素が最大縦幅より大きくならないように調整
            width  = Math.Min(div.offsetWidth + 25, maxWidth);
            height = Math.Min(div.offsetHeight, maxHeight);

            // ポップアップ位置を調整 (レスの右上に配置)
            Point point = PopupLocation;
            // NTwin23
            //if (img)
            //{
            //    point = new Point(point.X + adjustImg.X, point.Y + adjustImg.Y);
            //}
            // NTwin23

            // pointをクライアント座標に変換
            Point clientPos = new Point(
                point.X - body.scrollLeft,
                point.Y - body.scrollTop);

            // 上と左のはみ出しチェック
            if (clientPos.X < 0)
            {
                point.X = body.scrollLeft;
            }
            if (clientPos.Y < 0)
            {
                point.Y = body.scrollTop;
            }

            // 幅がクライアント幅を超えていたら調整
            if (clientPos.X + width > body.clientWidth)
            {
                int sub_w = (body.clientWidth - width);
                point.X = (body.scrollLeft + Math.Max(0, sub_w));
            }

            // 高さがクライアント幅を超えていたら調整
            if (clientPos.Y + height > body.clientHeight)
            {
                int sub_h = (body.clientHeight - height);
                point.Y = (body.scrollTop + Math.Max(0, sub_h));
            }

            // サイズを設定
            div.style.pixelLeft   = point.X;
            div.style.pixelTop    = point.Y;
            div.style.pixelWidth  = width;
            div.style.pixelHeight = height;

            // 色を設定
            div.style.backgroundColor = backColorHtml;
            div.style.color           = foreColorHtml;
            childCount++;
        }
Ejemplo n.º 27
0
        private void Browser_LoadCompleted(NavigationEventArgs e)
        {
            IHTMLDocument2 doc = (IHTMLDocument2)Browser.Document;
            IHTMLBodyElement body = (IHTMLBodyElement)doc.body;
            doc.charset = "utf-8";
            ((IHTMLElement3)body).contentEditable = "true";
            _body = (HTMLBody)doc.body;

            dynamic d = doc;
            d.attachEvent("onkeyup", _listener);
            d.attachEvent("onblur", _listener);
            d.attachEvent("onchange", _listener);
            d.attachEvent("oninput", _listener);
            d.attachEvent("onpaste", _listener);
            d.attachEvent("oncut", _listener);
        }
Ejemplo n.º 28
0
        private void btn_fillone_Click(object sender, EventArgs e)
        {
            if ("http://cwpt.suda.edu.cn/WFManager/login.jsp" != webBrowser1.Url.ToString())
            {
                MessageBox.Show("不正确的页面, 不要乱用功能!");
            }
            else if (username == "" || password == "")
            {
                MessageBox.Show("用户名或密码不完整!");
                return;
            }
            else
            {
                //根据验证码ID获取验证码元素
                HtmlElement ImageCodeTag = webBrowser1.Document.GetElementById("checkcodeImg");
                //获取网页所有内容
                HTMLDocument hdoc = (HTMLDocument)webBrowser1.Document.DomDocument;
                //获取网页body标签中的内容
                HTMLBody hbody = (HTMLBody)hdoc.body;
                //创建一个接口
                IHTMLControlRange hcr = (IHTMLControlRange)hbody.createControlRange();
                //获取图片地址
                IHTMLControlElement hImg = (IHTMLControlElement)ImageCodeTag.DomElement;
                //将图片添加到接口中
                hcr.add(hImg);
                //将图片复制到内存
                hcr.execCommand("Copy", false, null);
                //从粘贴板得到图片
                Image CodeImage = Clipboard.GetImage();
                //返回得到的验证码
                //CodeImage.Save("123.png");

                // 识别验证码
                byte[]        Buffer     = ImageToBytes(CodeImage);
                StringBuilder Result     = new StringBuilder('\0', 256);
                string        coderesult = "";
                if (GetImageFromBuffer(Buffer, Buffer.Length, Result))
                {
                    coderesult = Result.ToString();
                }
                else
                {
                    coderesult = "识别失败";
                }

                //填充用户名密码验证码
                HtmlElement name = webBrowser1.Document.GetElementById("uid");
                if (name != null)
                {
                    name.SetAttribute("value", username);
                }
                HtmlElement pass = webBrowser1.Document.GetElementById("pwd");
                if (pass != null)
                {
                    pass.SetAttribute("value", password);
                }
                HtmlElement code = webBrowser1.Document.GetElementById("chkcode");
                if (code != null)
                {
                    code.SetAttribute("value", coderesult);
                }

                HtmlElement loginbtn = webBrowser1.Document.GetElementById("loginbtn2");
                if (loginbtn != null)
                {
                    loginbtn.InvokeMember("click");
                }
            }
        }