设置ShowInTaskBar = False,在.net、winforms中关闭无模式窗体时会导致闪烁

发布于 2024-08-12 18:20:07 字数 1204 浏览 5 评论 0原文

要重新创建此行为,您需要创建一个具有以下属性的弹出窗体:

(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2024-08-19 18:20:07
-2139095040 = 0x80800000 = WS_POPUP | WS_BORDER

这似乎也是边界的罪魁祸首。

-2139095040 = 0x80800000 = WS_POPUP | WS_BORDER

This seems to be the culprit for the border too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文