简体   繁体   English

如何在 c# 应用程序的 showdialog() 上自动单击确定按钮?

[英]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我正在使用 windows 移动应用程序.. 正是它 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);
            }
        }

Just remove the line (actually, technically it's two lines) that shows the dialog from the source.只需从源中删除显示对话框的行(实际上,从技术上讲,它是两行)。

In general, trying to automatically click on buttons in your own application is a really bad idea.一般来说,尝试在您自己的应用程序中自动单击按钮是一个非常糟糕的主意。

If it's your code, just write your own message box class that contains a timer;如果是您的代码,只需编写您自己的包含计时器的消息框 class; it'll be the best solution.这将是最好的解决方案。

If the message box is displayed by someone other's code, you can:如果消息框由别人的代码显示,您可以:

  1. Use Windows Hooks to intercept msgbox arrearing使用Windows Hooks拦截msgbox欠费
  2. Just iterate through windows list using EnumWindows只需使用EnumWindows遍历 windows 列表

the solution for this case when i want to hide the capture dialog当我想隐藏捕获对话框时这种情况的解决方案

cameraDialog.Dispose();

after the end of if statements在 if 语句结束之后

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

cameraDialog.Dispose();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM