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

后端 未结 2 1066
名媛妹妹
名媛妹妹 2021-01-21 22:12

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. Ca

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-21 22:32

    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:

    enter image description here

提交回复
热议问题