gpt4 book ai didi

c# - 登录表单没有正确失去焦点

转载 作者:太空狗 更新时间:2023-10-29 21:55:20 27 4
gpt4 key购买 nike

我有一个主窗体是菜单的系统,它在加载时弹出一个登录窗体。最初它在菜单下方加载了登录表单,因此我使用 this.topmost = true 使其位于最前面。 (因为带到前面并发送到后面不起作用)

但是,如果用户随后点击其他东西,比如 chrome,那么根据最顶层的定义,它仍然停留在 z 顺序的顶部。

我尝试使用 deactivate 事件,但这意味着在加载时它会再次出现在菜单表单后面。

我怎样才能阻止它加载到我的菜单表单后面,而当它失去焦点时阻止它位于最顶部?

private void login_Deactivate(object sender, EventArgs e)
{
// do not want it to remain top most when the application is not in focus.
this.TopMost = false;
}

在菜单表单中:

private void Menu_Load(object sender, EventArgs e)
{
openLogin()
}

private void openLogin()
{
Cursor.Current = Cursors.WaitCursor;
login theForm = new login(this);
this.Enabled = false;
theForm.Show();
Cursor.Current = Cursors.Default;
theForm.Activate();
theForm.TopMost = true; // Make the login form display over the Menu
}

最佳答案

尝试设置登录表单 Owner菜单表单的属性。

来自上面的 MSDN 链接:

When a form is owned by another form, it is closed or hidden with the owner form. ... Owned forms are also never displayed behind their owner form. You can use owned forms for windows such as find and replace windows, which should not disappear when the owner form is selected. To determine the forms that are owned by a parent form, use the OwnedForms property

.

关于c# - 登录表单没有正确失去焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8196628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com