Click here to Skip to main content
13,000,469 members (58,465 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello again,

I am having a little bit of problem with my coding.
Basically I have a form(mainForm) where I have a button to select a video device which directs me to a new form(deviceForm). Then I choose a device from a comboBox(deviceBox) and press the "Select" button. This would redirect me back to the mainForm and display the video on a picture box(pictureBox1).

Here is where I am having difficulties with. I can't seem to redirect from deviceForm to mainForm and have the video displayed.
What code should I put in the "Select" button on deviceForm?
This is what I put in the code.

<pre lang="sql">public void btnSelect_Click(object sender, EventArgs e)<br />
       {<br />
           mainForm form1 = new mainForm();<br />
           selectDevice = new //VideoCaptureDevice(device[deviceBox.SelectedIndex].MonikerString);<br />
this.Hide();<br /><br />
       }</pre><br />

and in mainForm I have this for the picture box
private void pictureBox1(object sender, NewFrameEventArgs eventArgs)
                deviceForm form2 = new deviceForm();    
            selectDevice = new VideoCaptureDevice(device[form2.deviceBox.SelectedIndex].MonikerString);    
            Bitmap img = (Bitmap)eventArgs.Frame.Clone();
	            this.Image = img;

I was able to display feed from the webcam on a single form but I can't do it on another form.
I also included
<pre lang="cs">using AForge.Video;<br />
using AForge.Video.DirectShow;</pre><br />

On the mainForm, the code line
VideoCaptureDevice(device[form2.deviceBox.SelectedIndex].MonikerString); has an error on deviceBox, it says inaccessible due to it's protection.

Oh yeah, if this help I am using the latest version of AForge.Net framework and visual studio 2010 ultimate, running on vista sp3 and usb webcam of modal CrystalEye. Doing it on C#(obviously lol)

Hope the veterans can help me in solving this simple problem.
Posted 12-Feb-11 6:30am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

On your form2 you would have to make the variable deviceBox publicly accessible using the public access modifier. Better yet would be to make the deviceBox variable in form2 accessible through a property definition.
Best Regards,
lKENl 12-Feb-11 12:59pm
I did try making it public, but nothing happened when I ran the code. When I click the Select button, the deviceForm closes and the mainForm remains the same. Think it has something to do with either
Bitmap img = (Bitmap)eventArgs.Frame.Clone(); in the mainForm or the whole thing from the btn_Select in deviceForm. What I think should happen is that once we press "Select" the code closes the form, get the selected device and links it back to mainForm. I can't figure out what code should be written in Then again, once in the mainForm, there should be another code that accepts this, and the one written is probably wrong. Which is why I need help from everyone here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 12 Feb 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100