c# - 即使在 WinForms 中停用后,如何将子窗体保留在屏幕上?
问题描述
我的主窗体中有一个按钮。按下时,将出现子窗体。子表单充当通知。
通常,当任何(任何应用程序的)窗口打开时,如果我们单击另一个应用程序,打开的窗口将被停用并位于应用程序(我们单击的)后面。
但是当按下某些东西时(任何应用程序的)通知不会离开屏幕(或落后)。我想要那样的东西。
例子
Windows 中的“放大镜”应用程序在“放大镜”应用程序打开时单击另一个应用程序时不会出现在屏幕后面。
我想对子表单进行编码,以便即使在停用后它也不会离开屏幕。
我的代码(打开子表单)-
private void button2_Click(object sender, EventArgs e) {
this.Visible = false; // to make the main form invisible
for (int x = 0; x <= x++; x++) { //infinite loop
notificationForm n = new();
n.StartPosition = FormStartPosition.Manual;
n.Location = new Point(0, 0);
n.ShowDialog();
Task.Delay(3000).Wait(); // I made a for loop and included this line of code to open the notification(child form) every 3 seconds after closing it
}
}
解决方案
尝试将表单的 TopMost 属性设置为 true,如下所示:
private void button2_Click(object sender, EventArgs e) {
this.Visible = false; // to make the main form invisible
for (int x = 0; x <= x++; x++) { //infinite loop
notificationForm n = new();
n.StartPosition = FormStartPosition.Manual;
n.Location = new Point(0, 0);
n.TopMost = true;
n.ShowDialog();
Task.Delay(3000).Wait(); // I made a for loop and included this line of code to open the notification(child form) every 3 seconds after closing it
}
}
推荐阅读
- angular - 如何在焦点上显示自动完成选项
- excel - Excel 根据多个搜索条件查找多个唯一值
- kubernetes - Openshift Origin 3.6 删除 pod 总是与终结器一起挂起:-foregroundDeletion
- python - Selenium webdriver 无法在 Jupyter Notebook 的一个单元格中定位元素并将其定位在另一个单元格中
- bash - 如何尾随-F,但只保留最后5行的滚动输出
- kubernetes - 在最新的 0.7 版本中,OpenEBS Jiva 卷大小的单位是否有任何变化?
- javascript - 在 Angular 中使用第三个插件
- android - 如何使这张图片可点击以以编程方式重定向任何活动?
- javascript - 围绕三角形画布旋转圆圈
- c# - AutoMapper - 将派生类映射到 Dto