views:

191

answers:

2

Hi,

Suppose I have thread 1, the main window UI thread and thread 2, a login UI thread that is modal form.

Now thread 1 executes a piece of code and wants to change a UI element in the login form so it invokes a delegate to change something in thread 2. But when it does so, the login form becomes hidden behind the main window and there's no way for me to bring it back. Selecting it on the taskbar doesn't do anything and writing "Activate()" at the end of the invoked method doesn't do anything either.

How can I keep thread 2's UI from becoming hidden?

Thanks

+8  A: 

Call Focus() on your login form after you invoke to update the main window. Also it may help to set the parent window of the login form to be the main window when you display it.

(in your main UI class)

using (YourLoginForm f = new YourLoginForm()){

    YourLoginForm.Show(this)
}

Another approach may be to use ShowDialog() instead of Show(), and have your login form return a different DialogResult depending on whether the login was successful or not. ShowDialog() should automatically set your login form to be modal and have the focus.

Dale Halliwell
A: 

wow.... self pwn. k, the disappearing second window thing is a non-question

But the question in the comment still stands.... When I do ShowDialog in a second thread, how do I prevent the new window from acting separately from the main window? ie I don't want the user to minimize the main window while it's behind the second window. If another program comes up on top and hides everything, clicking the main window's icon in the taskbar has to bring up the second window with it etc

Xster
Don't add an answer to your own question unless it's actually an answer. Clarifying information should be added as a comment or edited into your original question.
bobbymcr