我在 WinForms 中实现了一个对话框,该对话框在屏幕右下角显示为通知对话框。问题是,无论何时显示,它都会获得焦点,并且只有当 TopMost = true 时才会发生这种情况。我该如何解决这个问题?
最佳答案
您需要继承 Form 并覆盖几个属性:
[Flags]
enum WS_EX
{
TOPMOST = 0x00000008,
}
class TopMostForm : Form
{
protected override CreateParams CreateParams
{
get
{
var baseParams = base.CreateParams;
baseParams.ExStyle |= (int)WS_EX.TOPMOST;
return baseParams;
}
}
protected override bool ShowWithoutActivation
{
get { return true; }
}
}
然后只需在此表单上简单地 Show() ,它将显示为最顶层且处于非事件状态。
关于TopMost = true 的 WinForms 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1727789/