调用 UI delegate 导致 UI 被隐藏

发布于 2024-08-08 16:04:21 字数 235 浏览 5 评论 0原文

假设我有线程 1(主窗口 UI 线程)和线程 2(模态形式的登录 UI 线程)。

现在线程 1 执行一段代码并想要更改登录表单中的 UI 元素,因此它调用委托来更改线程 2 中的某些内容。但是当它这样做时,登录表单会隐藏在主窗口后面,并且没有办法让我把它带回来。在任务栏上选择它不会执行任何操作,并且在调用的方法末尾写入“Activate()”也不会执行任何操作。

如何防止线程 2 的 UI 被隐藏?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何处潇湘 2024-08-15 16:04:21

调用 Focus()调用更新主窗口后登录表单。此外,当您显示登录表单时,将其父窗口设置为主窗口可能会有所帮助。

(在您的主 UI 类中)

using (YourLoginForm f = new YourLoginForm()){

    YourLoginForm.Show(this)
}

另一种方法可能是使用 ShowDialog() 而不是 Show(),并让您的登录表单返回不同的 DialogResult 取决于登录是否成功。 ShowDialog() 应该自动将您的登录表单设置为模式并具有焦点。

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.

幸福丶如此 2024-08-15 16:04:21

哇……自我pwn。 k,消失的第二个窗口的事情是没有问题的,

但评论中的问题仍然存在......
当我在第二个线程中执行 ShowDialog 时,如何防止新窗口与主窗口分开运行?即我不希望用户在第二个窗口后面时最小化主窗口。如果另一个程序出现在顶部并隐藏所有内容,则单击任务栏中的主窗口图标必须调出第二个窗口,等等

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文