2012-03-14 46 views
0

我想出了下面的代碼來產生一個「GROWL」效果,你可以在MAC和一些jQuery網站上看到。 (這樣的例子可以找到HERE。我使用的代碼效果很好,並顯示消息(s)很好。但是,我很難嘗試工作的問題是如何顯示當前消息ABOVE每個先前的消息還是那在屏幕上,並具有用於彈出每個消息定時器目前,它在同一時間關閉所有的消息框在VB.net應用程序中的GROWL效應

的代碼是這樣的:。

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 = 5 
    For a As Integer = 0 To _count 
     If _notifications.ContainsKey(a) Then 
      _notifications.Item(a).Top = _top 
      _top += _notifications.Item(a).Height + 5 
     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 

這是messagebox code本身:

Public Class msgWindow 
Public howLong As Integer 
Public theType As String 
Private loading As Boolean 
Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width 

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 

    Me.Width = intX 
    Me.Left = 0 
    Me.Top = 0 

    lblSaying.Width = Me.Width 
    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 - 300, 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.8 

     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 

Private Sub lblSaying_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSaying.Click 
    Me.opacityTimer.Stop() 
    Me.Close() 
End Sub 
End Class 

現在它將顯示以下舊帖子中的最新帖子。我需要更改什麼才能顯示最新的頂部,並隨着其他消息框的顯示繼續沿着列表的方向前進?

任何幫助將是偉大的!

大衛

回答

1

剛擡起頭,我相信低吼的Windows和咆哮都支持GNTP。這意味着你可以簡單地實現一個基於GNTP VB的庫(或者使用現有的庫)並與這些庫進行交談。 :)

+0

http://www.growlforwindows.com/gfw/developers.aspx#integration – SpoBo 2012-03-15 22:08:01