设置ShowInTaskBar = False,在.net、winforms中关闭无模式窗体时会导致闪烁
要重新创建此行为,您需要创建一个具有以下属性的弹出窗体:
(1) ShowInTaskBar = False
(2) 使用 Show 方法显示窗体并循环,直到窗体不可见。
(3) 为了在鼠标从窗体中单击时关闭窗体,请重写 OnDeactivate,并将visible 设置为False。
接下来,创建另一个窗体,单击按钮时将显示弹出窗口:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Syste
Using pop As New PopUp
pop.Visible = True
Do While pop.Visible
Application.DoEvents()
NativeMethods.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 250, &HFF, 4)
Loop
Me.Activate()
End Using
End Sub
启动项目,展开窗体以填充屏幕,然后单击按钮打开弹出窗口。 接下来单击返回原始表单中的任意位置。 大多数时候(但并非总是如此),原始形式会消失一瞬间,然后再次出现 - 从而导致闪烁效果。
深入研究 Reflector 和 System.Windows.Forms.Design.DropDownHolder 我在 CreateParams 中发现以下内容可以解决闪烁问题:
createParams.Style = (createParams.Style Or -2139095040)
不幸的是,它还在表单周围放置了黑色边框。 (您必须设置 FormBorderStyle = System.Windows.Forms.FormBorderStyle.None 才能看到这一点。)
除了在表单周围放置黑色边框之外,有谁知道这种样式的作用吗?
我用数字和十六进制等值搜索了谷歌,但什么也没找到。
谢谢。
预计到达时间:我在 pinvoke 查看了样式常量列表.net 但我并不明智。
To recreate this behaviour, you need to create a pop-up form with the following properties:
(1) ShowInTaskBar = False
(2) Display the form with the Show method and loop until the form is not Visible.
(3) In order to close the form when the mouse is clicked out of it, override OnDeactivate, and set visible to False.
Next, create another form that will display the pop-up when a button is clicked:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Syste
Using pop As New PopUp
pop.Visible = True
Do While pop.Visible
Application.DoEvents()
NativeMethods.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 250, &HFF, 4)
Loop
Me.Activate()
End Using
End Sub
Start the project, expand the form to fill the screen, and click the button to open the pop-up.
Next click back onto anywhere in the original form.
Most times, but not always, the original form will disappear for a split second before reappearing again - thus causing a flicker effect.
Delving into reflector and System.Windows.Forms.Design.DropDownHolder I found the following in CreateParams that solves the flicker issue:
createParams.Style = (createParams.Style Or -2139095040)
Unfortunately, it also puts a black border around the form. (You'll have to set FormBorderStyle = System.Windows.Forms.FormBorderStyle.None to see this.)
Does anyone have any idea what this style does apart from putting the black border round the form?
I've searched google with the number and the hex equivalent but can find nothing.
Thanks.
ETA: I've had a look at a list of style constants at pinvoke.net but I'm non the wiser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎也是边界的罪魁祸首。
This seems to be the culprit for the border too.