Make a screen blink / flash to alert user

2019-06-26 12:55发布

问题:

Using .NET 3.5 Winforms, How would i make the entire screen flash/blink between red and white for just a second.

I have a big screen that's only meant to show status on monitored equipment. I would like it to flash as a notification to users when an event occurs that they should be looking at.

Thank you

回答1:

Use what tbischel has suggested. Here is some sample code for the timer.

Private TickCount As Integer = 0
Private Const NUMBER_OF_SECONDS As Integer = 1

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Me.BackColor = If(Me.BackColor = Color.White, Color.Red, Color.White)
    TickCount += 1

    If TickCount >= NUMBER_OF_SECONDS * 1000 / Timer1.Interval Then
        Timer1.Stop()
        Me.BackColor = Color.Gray
        Me.TopMost = False
        Me.WindowState = FormWindowState.Normal
    End If
End Sub

It will alternate between Red and White and whatever interval you specify for your timer. It will stop after how ever many seconds you give it. When it is done it sets the color to grey, removes the .TopMost flag and sets the WindowState back to normal.

Having said that; it's really annoying :)



回答2:

you could create a blank maximized form with the FormBorderStyle set to FormBorderStyle.None, and set the background color on a timer.