I need to programmatically click ok button on a dialog. I've already made a snippet with out clicking the dialog. I'm aware theoretically should not be needed but for some reason it only works if you click "OK" for certain features.
Snippet 1:
ConnPropsForm propsForm = new ConnPropsForm();
editOutput.Text = "";
propsForm.editUsername.Text = User;
propsForm.editPassword.Text = Password;
propsForm.editAddress.Text = _HOST;
propsForm.editPort.Value = Convert.ToInt32(_PORT);
propsForm.txtPrivateKey.Text = string.Empty;
propsForm.txtPrivateKeyPassword.Text = string.Empty;
propsForm.txtTrustedKeys.Text = string.Empty;
client.Username = propsForm.editUsername.Text;
client.Password = propsForm.editPassword.Text;
client.TrustedKeysFile = propsForm.txtTrustedKeys.Text;
Snippet 1 is just setting up the Dialog Box. Nothing special here
Snippet 2:
if (propsForm.ShowDialog(this) == DialogResult.OK)
{
editOutput.Text = "";
client.Username = propsForm.editUsername.Text;
client.Password = propsForm.editPassword.Text;
if (propsForm.txtPrivateKey.Text != "")
{
try
{
Sshkeymanager keymanager = new Sshkeymanager();
keymanager.ImportFromFile(propsForm.txtPrivateKey.Text, propsForm.txtPrivateKeyPassword.Text);
client.Key = keymanager.Key;
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
}
client.TrustedKeysFile = propsForm.txtTrustedKeys.Text;
try
{
client.Connect(propsForm.editAddress.Text, (int)propsForm.editPort.Value);
LoadRoot();
UpdateControls();
}
catch (Exception E)
{
MessageBox.Show(E.Message);
}
}
Snippet 2 is the magic. I want to test and see if "clicking OK makes a difference. Currently troubleshooting an issue with a bot i'm building. In case your wondering. The bots job is to literally just update a password every 30 days. In a perfect world I would not need a dialog and not need to click Ok button programmatically but the IT gods are mad at me currently. I thought about doing a loop to loop through each control until I found the "btnOk" button but I hope there is a better way.

In Winforms, if you have direct access to the button from where this is running you can just do this: