本文介绍了WinForms对话框与TopMost = true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在WinForms中实现的对话框,在屏幕右下方显示为通知对话框。问题是,每当显示它需要重点,只有当TopMost = true时才会发生这种情况。如何解决这个问题?解决方案
您需要从Form继承并覆盖几个属性:
[Flags]
枚举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()它将显示为最高和无效。
I have a dialog implemented in WinForms that is shown as a notify dialog on the bottom right of the screen. The problem is that whenever is shown it takes the focus and this happens only when TopMost = true. How can I solve this?
解决方案
You need to inherit from Form and override a couple of properties:
[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; }
}
}
Then just simply Show() on this form and it will be displayed as topmost and inactive.
这篇关于WinForms对话框与TopMost = true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!