Copy image from the Web browser control and show it in an Image control in wpf c #

0

Very good community I am developing an application and I have this problem that I have not been able to solve, I hope you can help me.

My need is to copy a captcha image of my WebBrowser control to the Clipboard and show it in an Image control, but it does not show me anything. My code is as follows and does not present any errors.

 //Navegacion del WebBrowser
 private void Window_Loaded_1(object sender, RoutedEventArgs e)
    {
        wb.Navigate("https://portalcfdi.facturaelectronica.sat.gob.mx/");
    }


  private void wb_LoadCompleted(object sender, NavigationEventArgs e)
    {
        this.captcha();
    }


 private void captcha() {

      mshtml.IHTMLDocument2 doc = (IHTMLDocument2)wb.Document; 

      mshtml.IHTMLControlRange imgRng = (mshtml.IHTMLControlRange)((mshtml.HTMLBody)doc.body).createControlRange();

        foreach (IHTMLElement elemento in doc.images)
        {
            string ruta = elemento.getAttribute("src");                
            if (ruta.Contains("/jcaptcha.jpg"))
            {
                imgRng.add((mshtml.IHTMLControlElement)elemento);
                imgRng.execCommand("Copy", false, null);                    

                if (Clipboard.ContainsImage())
                {
                    imgC.Source = Clipboard.GetImage();
                }


            }

        }
    }
    
asked by SHINOBI 01.04.2018 в 02:33
source

0 answers