Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在webBrowser1\u DocumentCompleted中调用my函数不会完成浏览器的加载_C#_Webbrowser Control - Fatal编程技术网

C# 在webBrowser1\u DocumentCompleted中调用my函数不会完成浏览器的加载

C# 在webBrowser1\u DocumentCompleted中调用my函数不会完成浏览器的加载,c#,webbrowser-control,C#,Webbrowser Control,我想在视频的前30秒拍摄Screenshot()。但当我在webBrowser1_DocumentCompleted中调用它时,它会停止加载视频。所以截图将是空白的。这只是我代码的一个粗略副本。是否有一种方法可以在所有内容都完全加载并播放视频后调用TakeScreenshot()?或者在newForm.ShowDialog()之后调用它 (将评论作为答案,以允许问题结束) 我很确定你链接的视频是Adobe Flash。然而,这可能有效 我很确定你链接的视频是Adobe Flash。不过可能有用。

我想在视频的前30秒拍摄Screenshot()。但当我在webBrowser1_DocumentCompleted中调用它时,它会停止加载视频。所以截图将是空白的。这只是我代码的一个粗略副本。是否有一种方法可以在所有内容都完全加载并播放视频后调用TakeScreenshot()?或者在newForm.ShowDialog()之后调用它

(将评论作为答案,以允许问题结束)


我很确定你链接的视频是Adobe Flash。然而,这可能有效

我很确定你链接的视频是Adobe Flash。不过可能有用。谢谢你提供的信息。我能将硒元素与我的表格结合起来吗?我是否可以运行多个selenium?我对selenium不是很有经验。我知道它可以在任何需要WebBrowser的地方使用,并且可以有多个实例。我建议您在上查看参考资料,以获得更具体的信息。谢谢。我去看看。
main(
Form1 newForm = new Form1();
newForm.loadStream();           
newForm.ShowDialog();

}

public void loadVideo()
    {
        //// When the form loads, open this web page.
        //this.webBrowser1.Navigate("http://www.dotnetperls.com/");

        SuppressScriptErrorsOnly(webBrowser1);

    //set browser eumulator to IE8
        var appName = Process.GetCurrentProcess().ProcessName + ".exe";
        SetIE8KeyforWebBrowserControl(appName);


        webBrowser1.Navigate("http://youtu.be/e-ORhEE9VVg?list=PLFgquLnL59alLAsVmUulfe3X-BrPzoYAH");
        webBrowser1.ScriptErrorsSuppressed = true;
        //Console.WriteLine("loading new new");
    }

public void takeScreenShoot()
    {           

        DateTime startTime = DateTime.Now;
        int i = 0;
        string location = @"F:\Twitch Screenshoot\testing\";

            while (true)
            {

                //If time is greater than 30 seconds start taking picture
                if (DateTime.Now.Subtract(startTime).TotalSeconds > 1) 
                {
                    if (DateTime.Now.Subtract(startTime).TotalSeconds > i + 1)
                    {
                        Console.WriteLine("Taking Picture\n");
                        // The size of the browser window when we want to take the screenshot (and the size of the resulting bitmap)
                        Bitmap bitmap = new Bitmap(1024, 768);
                        Rectangle bitmapRect = new Rectangle(0, 0, 1024, 768);
                        // This is a method of the WebBrowser control, and the most important part

                        this.webBrowser1.DrawToBitmap(bitmap, bitmapRect);


                        // Generate a thumbnail of the screenshot (optional)
                        System.Drawing.Image origImage = bitmap;
                        System.Drawing.Image origThumbnail = new Bitmap(120, 90, origImage.PixelFormat);

                        Graphics oGraphic = Graphics.FromImage(origThumbnail);
                        oGraphic.CompositingQuality = CompositingQuality.HighQuality;
                        oGraphic.SmoothingMode = SmoothingMode.HighQuality;
                        oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        Rectangle oRectangle = new Rectangle(0, 0, 120, 90);
                        oGraphic.DrawImage(origImage, oRectangle);

                        // Save the file in PNG format

                        origThumbnail.Save(location + "Screenshot" + i + ".png", ImageFormat.Png);

                        origImage.Dispose();
                        i++;
                    }
                }

                //stop taking picture when time is greater than 3.
                if (DateTime.Now.Subtract(startTime).TotalMinutes > 1)
                {
                    //should close form here
                    this.Close();
                    break;
                }               
            }        
    }

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {

    if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath)
        {
            var webBrowser = sender as WebBrowser;
            webBrowser.DocumentCompleted -= webBrowser1_DocumentCompleted;
            Console.WriteLine("loading {0} \n");
            this.takeScreenShoot();

        }          

    }