即使在 WinForms 中停用后,如何将子窗体保留在屏幕上?
How to keep the child form on screen even after deactivation in WinForms?
我的主窗体中有一个按钮。按下时,子窗体出现。子表单充当通知。
通常,当任何 Window(任何应用程序的)打开时,如果我们单击另一个应用程序,打开的 window 将被停用并进入(我们单击的)应用程序后面。
但是当按下某些东西时,(任何应用程序的)通知不会离开屏幕(或落后)。我想要这样的东西。
例子
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
}
}
我的主窗体中有一个按钮。按下时,子窗体出现。子表单充当通知。
通常,当任何 Window(任何应用程序的)打开时,如果我们单击另一个应用程序,打开的 window 将被停用并进入(我们单击的)应用程序后面。
但是当按下某些东西时,(任何应用程序的)通知不会离开屏幕(或落后)。我想要这样的东西。
例子
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
}
}