VB.NET - Background fade like in the UAC message?

巧了我就是萌 提交于 2019-12-31 03:49:14

问题


Hello,

When the UAC message is displayed in Windows Vista, 7 or 8 the background becomes inaccessible until the user selects from the message dialog. Can this be done with VB.NET program to make the background inaccessible until the user selects from the Form?

What I want is what happens to the background when UAC or similar message is shown like the image below,


回答1:


That's pretty easy to do, just display a black borderless form with opacity and the dialog on top of it. Do keep in mind that this of course cannot provide the same level as protection as the UAC prompt provides, you cannot use the secure desktop yourself.

Public Shared Function Plexiglass(dialog As Form) As DialogResult
    Using plexi = New Form()
        plexi.FormBorderStyle = FormBorderStyle.None
        plexi.Bounds = Screen.FromPoint(dialog.Location).Bounds
        plexi.StartPosition = FormStartPosition.Manual
        plexi.AutoScaleMode = AutoScaleMode.None
        plexi.ShowInTaskbar = False
        plexi.BackColor = Color.Black
        plexi.Opacity = 0.45
        plexi.Show()
        dialog.StartPosition = FormStartPosition.CenterParent
        Return dialog.ShowDialog(plexi)
    End Using
End Function

Tweak the Opacity value as desired, the higher the value the darker the background. Looks like this on a little test program:




回答2:


You are looking for ShowDialog(). This means it will bring the control in front of others and here's a quick example.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim nform As New Form
    nform.Text = "Test Form"
    nform.ShowDialog()
End Sub

If you use BringToFront() method all this will do is bring it to front in the z-order. Same with TopMost(), but the only difference in TopMost() is that window will always be at top.

Thanks! MrCodexer



来源:https://stackoverflow.com/questions/20040904/vb-net-background-fade-like-in-the-uac-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!