gpt4 book ai didi

c# - 应用程序中的窗口始终位于顶部

转载 作者:行者123 更新时间:2023-11-30 20:39:06 25 4
gpt4 key购买 nike

要使我的 winforms 窗口始终保持在顶部,我可以使用:

TopMost = true;

但这将使窗口始终保持在顶部。我希望它只在应用程序中保持在顶部。因此,当我最小化我的应用程序或更改应用程序时,我不希望它再停留在顶部。

最佳答案

我认为您正在寻找 Form.Owner属性

To make a form owned by another form, assign its Owner property a reference to the form that will be the owner.

When a form is owned by another form, it is closed or hidden with the owner form. For example, consider a form named Form2 that is owned by a form named Form1. If Form1 is closed or minimized, Form2 is also closed or hidden.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.

如果您没有从“应用程序窗口”显示子窗体,访问应用程序窗口(也称为主窗体)的最简单方法是使用类似这样的东西

static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(MainForm = new MyAppForm());
}
public static MyAppForm MainForm { get; private set; }
}

然后

var childForm = new MyChildForm();
childForm.Owner = Program.MainWindow;
//childForm.ShowInTaskbar = false;
childForm.Show();

关于c# - 应用程序中的窗口始终位于顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34606238/

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