Search code examples
c#buttonshowdialog

how to make automatic click ok button on showdialog() on c# application?


I'm using a windows mobile application .. exactly it's Microsoft.WindowsMobile.Samples.CECamera

When I capture an image a dialog form appears to tell it's successfully captured and I should click ok. In the code, it uses this ok click to continue saving the picture ... Now I want this message to stop appearing. or any other method to make an automatic click on that ok button.

 if (DialogResult.OK == cameraCapture.ShowDialog())
            {
                string fileName = cameraCapture.FileName;

                // If it is a video we rename the file so that it has the user entered
                // default filename and the correct extension.
                if (cameraCapture.Mode != CameraCaptureMode.Still)
                {
                    string extension = fileName.Substring(fileName.LastIndexOf("."));
                    string directory = "";

                    if (fileName.LastIndexOf("\\") != -1)
                    {
                        directory = fileName.Substring(0, fileName.LastIndexOf("\\") + 1);
                    }

                    fileName = directory + this.textDefaultFileName.Text + extension;

                    System.IO.File.Move(cameraCapture.FileName, fileName);
                }

                // The method completed successfully.
                MessageBox.Show("The picture or video has been successfully captured and saved to:\n\n" + fileName,
                    this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            }
        }

Solution

  • the solution for this case when i want to hide the capture dialog

    cameraDialog.Dispose();
    

    after the end of if statements

    if (DialogResult.OK == cameraCapture.ShowDialog())
    {
        //plapla
    }
    
    cameraDialog.Dispose();