Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
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.
public void btnSelect_Click(object sender, EventArgs e)
           mainForm form1 = new mainForm();
           selectDevice = new //VideoCaptureDevice(device[deviceBox.SelectedIndex].MonikerString);

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
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.
Posted 12-Feb-11 7: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 at 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
0 OriginalGriff 445
1 Sergey Alexandrovich Kryukov 322
2 Maciej Los 275
3 CHill60 195
4 King Fisher 179
0 OriginalGriff 240
1 Maciej Los 95
2 Sascha Lefévre 85
3 King Fisher 70
4 F-ES Sitecore 55

Advertise | Privacy | Mobile
Web03 | 2.8.150331.1 | Last Updated 12 Feb 2011
Copyright © CodeProject, 1999-2015
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