forms("main") 就是主窗口,有些时候项目还没完全打开,就突然会报错,提示 main窗口不存在
下面代码是在 SystemIdle 事件中的
If Forms("Main").Opened = True Then
Static OpenQQ As WinForm.Button = Forms("Main").Controls("OpenQQ")
Static LastTime As Date
Dim txt As String
If QQClient.Ready
If QQClient.UnreadCount > 0 Then
txt = "(" & QQClient.UnreadCount & "条)"
End If
End If
If OpenQQ.Text <> txt Then
OpenQQ.Text = txt
End If
If OpenQQ.Text > "" Then
Dim ntp As timeSpan = Date.Now - LastTime
If ntp.TotalSeconds >= 0.5 Then
LastTime = Date.Now
If OpenQQ.ForeColor = Color.Red Then
OpenQQ.ForeColor = Color.Transparent
Else
OpenQQ.ForeColor = Color.Red
End If
End If
End If
Else
Return
End If