Click here to Skip to main content
16,013,605 members
Please Sign up or sign in to vote.
5.00/5 (1 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.

SQL
public void btnSelect_Click(object sender, EventArgs e)
       {
           mainForm form1 = new mainForm();
           selectDevice = new //VideoCaptureDevice(device[deviceBox.SelectedIndex].MonikerString);
this.Hide();
form1.show(????)
       }



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
C#
using AForge.Video;
using AForge.Video.DirectShow;



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.
Thanks
Posted

1 solution

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,
Manfred
 
Share this answer
 
v2
Comments
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 form1.show(???). 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900