c# - How to execute main form button function to second form? -
i have function in button of main form start camera when click, want start function execute in second form function contains conditional statement if , else. make public void name , put function inside after make constructor in second form call function time doesn't work. how do other way?
public void startprog() { if (start.text == "&start") { if (deviceexist) { videosource = new videocapturedevice(videodevices[combobox1.selectedindex].monikerstring); videosource.newframe += new newframeeventhandler(video_newframe); closevideosource(); videosource.desiredframesize = new size(1366, 768); //videosource.desiredframerate = 10; videosource.start(); lblcam.text = "device running..."; start.text = "&stop"; } else { lblcam.text = "error: no device selected."; } } else { if (videosource.isrunning) { closevideosource(); lblcam.text = "device stopped."; start.text = "&start"; } } } private void start_click(object sender, eventargs e) { startprog(); } in second form
private void close(object sender, formclosingeventargs e) { frmmain main = new frmmain(); main.startprog(); }
although did not point out why "doesn't work" or how fails, i'd recommend create event in second form first form subscribes (see events tutorial). fire event in second form, first form execute same action when press button.
Comments
Post a Comment