jQuery在VB.net中“类似于咆哮”的效果

时间:2010-04-21 04:06:23

标签: vb.net visual-studio-2008

嘿所有,我做了一个简单的形式,模仿这里看到的jQuery“GROWL”效果http://www.sandbox.timbenniks.com/projects/jquery-notice/

然而,我遇到了一个问题。如果我有一个以上的调用表单来显示“低吼”,那么它只是用我发送的任何电话刷新相同的表格。换句话说,我一次只能显示一个表单,而不是只有一个表单下拉,而新表单就会出现在它上面。

以下是“GROWL”表单的简单表单代码:

Public Class msgWindow
Public howLong As Integer
Public theType As String
Private loading As Boolean

Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs)
    Dim pn As New Pen(Color.DarkGreen)

    If theType = "OK" Then
        pn.Color = Color.DarkGreen
    ElseIf theType = "ERR" Then
        pn.Color = Color.DarkRed
    Else
        pn.Color = Color.DarkOrange
    End If

    pn.Width = 2
    pe.Graphics.DrawRectangle(pn, 0, 0, Me.Width, Me.Height)
    pn = Nothing
End Sub

Public Sub showMessageBox(ByVal typeOfBox As String, ByVal theMessage As String)
    Me.Opacity = 0
    Me.Show()
    Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 350, 15)

    Me.loading = True
    theType = typeOfBox
    lblSaying.Text = theMessage

    If typeOfBox = "OK" Then
        Me.BackColor = Color.FromArgb(192, 255, 192)
    ElseIf typeOfBox = "ERR" Then
        Me.BackColor = Color.FromArgb(255, 192, 192)
    Else
        Me.BackColor = Color.FromArgb(255, 255, 192)
    End If

    If Len(theMessage) <= 30 Then
        howLong = 4000
    ElseIf Len(theMessage) >= 31 And Len(theMessage) <= 80 Then
        howLong = 7000
    ElseIf Len(theMessage) >= 81 And Len(theMessage) <= 100 Then
        howLong = 12000
    Else
        howLong = 17000
    End If

    Me.opacityTimer.Start()
End Sub

Private Sub opacityTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opacityTimer.Tick
    If Me.loading Then
        Me.Opacity += 0.07

        If Me.Opacity >= 0.8 Then
            Me.opacityTimer.Stop()
            Me.opacityTimer.Dispose()
            Pause(howLong)
            Me.loading = False
            Me.opacityTimer.Start()
        End If
    Else
        Me.Opacity -= 0.08

        If Me.Opacity <= 0 Then
            Me.opacityTimer.Stop()
            Me.Close()
        End If
    End If
End Sub

Public Sub Pause(ByVal Milliseconds As Integer)
    Dim dTimer As Date

    dTimer = Now.AddMilliseconds(Milliseconds)

    Do While dTimer > Now
        Application.DoEvents()
    Loop
End Sub
End Class

我通过这个简单的电话呼叫表格:

Call msgWindow.showMessageBox("OK", "Finished searching images.")

有没有人知道我可以使用相同设置的方式但是允许我添加任意数量的表单而不会一遍又一遍刷新相同的表单?

像往常一样,任何帮助都会很棒! :)

大卫

1 个答案:

答案 0 :(得分:1)

这是实现目标的一种方式,尽管可能有更好的方法来管理它。

Public Class Growl

Private _notifications As New Dictionary(Of Integer, msgWindow)
Private _count As Integer = 0

Public Sub Remove(ByVal Sender As msgWindow, ByVal e As EventArgs)
    _notifications.Remove(CInt(Val(Sender.Name.Substring(1))))
    RefreshPositions()
End Sub

Private Sub RefreshPositions()
    Dim _top As Integer = 15
    For a As Integer = 0 To _count
        If _notifications.ContainsKey(a) Then
            _notifications.Item(a).Top = _top
            _top += _notifications.Item(a).Height + 20
        End If
    Next
End Sub

Public Sub ShowMessageBox(ByVal typeOfNotification As String, ByVal msg As String)
    Dim x As New msgWindow
    x.Name = "m" & _count
    AddHandler x.FormClosed, AddressOf Remove
    _notifications(_count) = x
    _count += 1
    x.showMessageBox(typeOfNotification, msg)
    RefreshPositions()
End Sub

End Class

在您的代码中,声明:

Dim g as New Growl

并致电

g.showMessageBox( ... , ... )

而不是

msgWindow.showMessageBox( ... , ... )

希望这有帮助。