Having some trouble finding an answer to this specific situation. I need to create a temporary form (that will later be destroyed) that is in a separate thread from the main form.
This form is used for displaying account login information to the user. At the same time this form is on screen, a modal input box is also displayed to the user. The presence of the modal input box prevents any interaction with the login info form (copying/pasting), which is necessary functionality for the user.
How can I:
A) Create and display a new Form on an entirely separate thread from the main Form?
B) Destroy that Form from the main Form's thread once the user has entered input into the modal dialog box?
Note: I have already explored MainForm.Invoke/BeginInvoke and this does not give the results I need, as some other posts have claimed it should.
The code for the modal InputBox:
class InputBox
{
public static DialogResult Show(string prompt, bool hideInput, out string userInput, Form parent = null)
{
InputBoxForm frm = new InputBoxForm(prompt, hideInput);
if (parent != null)
frm.ShowDialog(parent);
else
frm.ShowDialog();
if (frm.DialogResult == DialogResult.OK)
{
userInput = frm.txtInput.Text;
frm.Dispose();
return DialogResult.OK;
}
else
{
userInput = "";
frm.Dispose();
return DialogResult.Cancel;
}
}
}
And the code as it is used in the program:
Form loginDisplay = LoginInfoForm(user, pass);
loginDisplay.Show(null);
string input = "";
InputBox.Show("Enter info:", false, out input, parent: this);
The LoginInfoForm
is just a function that dynamically creates a form and formats it a bit.