hi
im doing program that capture image and send the image for my email
the only way that this code work - when i doing Button and click - and that send for my email
but when i write all the code in the Form1_Load - that give me eror/
this is the code:

Form1_Load Function:

 webcam.Start();
imgCapture.Image = imgVideo.Image; //(imgCapture and imgVideo == PictureBox)
imgCapture.Image.Save(@"d:\SavedImage.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
....... // etc....

and that give me eror
but when i write only webcam.Start(); in Form1_Load and the other code in button click
that work
how i can to do that? non button click!
thanks...

Not really 100% sure I know what you are doing...

But, the load function only runs once, when the form is first loaded, after that it won't run again unless you specifically call it from some other method or event.

Look into timers if you are trying to capture images using a set interval.

Maybe the error occures this line:

imgCapture.Image = imgVideo.Image;

if imgVideo is a pictureBox, there is no image inside of this control yet, thats why you get this error.
Try putting this code into OnShow() overriden method.

Just create (write) this event:

protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            //youe code in here
        }

But there can still occur this same error, if there will be on image in the pictureBox.
bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.