Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I having profile creation form which contains opwn webcam button ,once i click it will take image via webcam in another form picturebox.i need to pass the picture box image to already loaded form.with using show()

What I have tried:

Profile creation form buttonclick
C#
private void Button1_Click(object sender, EventArgs e)
      {
          ProfilepictureCapture imc = new ProfilepictureCapture();
          imc.ShowDialog(this);

          //ProfilepictureCapture pictureForm = new ProfilepictureCapture();
          //pictureForm.MyFirstForm = this;
          //pictureForm.Show();
      }

Capture image form btnclick
C#
private void btnCapture_Click(object sender, EventArgs e)
       {
           pictureBox2.Image = imgVideo.Image;
       }

       private void btnok_Click(object sender, EventArgs e)
       {


           NewClient pictureSource=new NewClient();
           pictureSource.PBProfilePic.Image = this.pictureBox2.Image;

           this.Hide();
       }
Posted
Updated 20-Oct-16 0:19am

1 solution

Because you create a new instance of the form each time you click Button1, you shouldn't Hide it - instead, go to the ProfilepictureCapture form, and set the DialogResult property of the btnok button to DialogResult.OK
Now, when the user clicks the OK button, the form will close and control will return to the original form.
Add a property to the ProfilepictureCapture form:
C#
public Image ProfilePic
   {
   get { return pictureBox2.Image; }
   }
And then use that property in your calling form:
C#
private void Button1_Click(object sender, EventArgs e)
      {
          ProfilepictureCapture imc = new ProfilepictureCapture();
          if (imc.ShowDialog(this) == DiralogResult.OK)
          {
              Image myPicture = imc.ProfilePic;
              ...
          }
      }
 
Share this answer
 

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