Skip to content

Examples

Practical examples for various usage scenarios of cToast.

Table of Contents

Basic Examples

1. Simple Information Notification

vb
With New cToast
    .Show "This is a simple information notification"
End With

2. Success Notification with Title

vb
With New cToast
    .State(Success).Show "File saved successfully", 2000, "Success"
End With

3. Warning Notification with Custom Duration

vb
With New cToast
    .State(Warning).Show "Disk space is running low", 5000, "Warning"
End With

4. Error Notification

vb
With New cToast
    .State(Danger).Show "Operation failed, please try again", 3000, "Error"
End With

5. Dark Theme Notification

vb
With New cToast
    .Theme(Dark).State(Info).Show "Dark theme notification", 2000
End With

6. Persistent Display (No Auto Close)

vb
With New cToast
    .State(Info).Show "This message will not auto-close", 0, "Important"
End With

7. Long Text Content

vb
Dim msg As String
msg = "This is a long message that may span multiple lines. " & _
      "cToast automatically handles text wrapping and display."

With New cToast
    .State(Info).Show msg, 5000, "Long Message"
End With

8. Empty Title (No Title Display)

vb
With New cToast
    .Show "Notification without title", 2000, ""
End With

9. Empty Content (Only Title)

vb
With New cToast
    .Show "", 2000, "Title Only"
End With

10. Very Short Duration (1 Second)

vb
With New cToast
    .State(Success).Show "Quick flash", 1000, "Quick"
End With

Position Control Examples

11. Top-Left Corner Display

vb
With New cToast
    .Pos(LeftTop).State(Info).Show "Top-left notification", 2000
End With

12. Top-Right Corner Display

vb
With New cToast
    .Pos(RightTop).State(Success).Show "Top-right notification", 2000
End With

13. Bottom-Left Corner Display

vb
With New cToast
    .Pos(LeftBottom).State(Warning).Show "Bottom-left notification", 2000
End With

14. Bottom-Right Corner Display

vb
With New cToast
    .Pos(RightBottom).State(Danger).Show "Bottom-right notification", 2000
End With

15. Center Display

vb
With New cToast
    .Pos(Center).State(Info).Show "Center notification", 3000, "Center"
End With

16. Top-Center Display

vb
With New cToast
    .Pos(CenterTop).State(Success).Show "Top-center notification", 2000
End With

17. Bottom-Center Display

vb
With New cToast
    .Pos(CenterBottom).State(Warning).Show "Bottom-center notification", 2000
End With

18. Left-Center Display

vb
With New cToast
    .Pos(LeftCenter).State(Info).Show "Left-center notification", 2000
End With

19. Right-Center Display

vb
With New cToast
    .Pos(RightCenter).State(Danger).Show "Right-center notification", 2000
End With

State and Theme Examples

20. All Four States

vb
' Information
With New cToast
    .Pos(RightTop).State(Info).Show "Information message", 2000, "Info"
End With

' Success
With New cToast
    .Pos(RightTop).State(Success).Show "Success message", 2000, "Success"
End With

' Warning
With New cToast
    .Pos(RightTop).State(Warning).Show "Warning message", 2000, "Warning"
End With

' Danger
With New cToast
    .Pos(RightTop).State(Danger).Show "Error message", 2000, "Error"
End With

21. Light Theme (Default)

vb
With New cToast
    .Theme(Light).State(Info).Show "Light theme message", 2000
End With

22. Dark Theme

vb
With New cToast
    .Theme(Dark).State(Info).Show "Dark theme message", 2000
End With

23. State + Theme Combination

vb
' Dark theme + Success
With New cToast
    .Theme(Dark).State(Success).Show "Dark + Success", 2000
End With

' Dark theme + Danger
With New cToast
    .Theme(Dark).State(Danger).Show "Dark + Danger", 2000
End With

' Light theme + Warning
With New cToast
    .Theme(Light).State(Warning).Show "Light + Warning", 2000
End With

Stacking Management Examples

24. Top-Right Auto Stacking (Sequential)

vb
With New cToast
    .Pos(RightTop)
    
    ' Messages will stack from top to bottom
    .State(Info).Show "First message", 0
    .State(Success).Show "Second message", 0
    .State(Warning).Show "Third message", 0
    .State(Danger).Show "Fourth message", 0
End With

25. Bottom-Center Auto Stacking (Reverse)

vb
With New cToast
    .Pos(CenterBottom)
    
    ' Messages will stack from bottom to top (reverse)
    .State(Info).Show "First message (bottom)", 0
    .State(Success).Show "Second message", 0
    .State(Warning).Show "Third message", 0
    .State(Danger).Show "Fourth message (top)", 0
End With

26. Manual Stacking Index

vb
With New cToast
    .Pos(RightTop)
    
    ' Specify stack index manually
    .InstIndex(0).State(Info).Show "Message at index 0", 0
    .InstIndex(1).State(Success).Show "Message at index 1", 0
    .InstIndex(2).State(Warning).Show "Message at index 2", 0
End With

27. Batch Stacking in Loop

vb
Dim i As Integer
Dim Toast As New cToast

Toast.Pos(RightTop)

For i = 1 To 5
    Toast.State(Info).Show "Message " & i, 3000, "Batch"
Next i

28. Named Popup Management

vb
Dim Toast As New cToast

' Display named popups
Toast.Tag("msg1").Pos(RightTop).State(Info).Show "Message 1", 0
Toast.Tag("msg2").Pos(RightTop).State(Success).Show "Message 2", 0
Toast.Tag("msg3").Pos(RightTop).State(Warning).Show "Message 3", 0

' Close specific popup
Toast.CloseMe "msg2"

' Check if exists
If Toast.Exists("msg1") Then
    Debug.Print "msg1 still exists"
End If

29. Batch Close All

vb
Dim Toast As New cToast

' Display multiple popups
Toast.Pos(RightTop).State(Info).Show "Message 1", 0
Toast.Pos(RightTop).State(Success).Show "Message 2", 0
Toast.Pos(RightTop).State(Warning).Show "Message 3", 0

' Close all at once
Toast.CloseAll

30. Get Active Popup List

vb
Dim Toast As New cToast
Dim Keys As Collection
Dim Key As Variant

' Display some popups
Toast.Pos(RightTop).State(Info).Show "Message 1", 0
Toast.Pos(RightTop).State(Success).Show "Message 2", 0

' Get all active popups
Set Keys = Toast.ActiveKeys

Debug.Print "Total popups: " & Toast.Count

For Each Key In Keys
    Debug.Print "Active popup: " & CStr(Key)
Next Key

31. Conditional Close

vb
Dim Toast As New cToast

Toast.Tag("important").State(Danger).Show "Important message", 0
Toast.Tag("normal").State(Info).Show "Normal message", 0

' Close specific popups
Toast.CloseMe "normal"

' Only important message remains

Event Listener Examples

32. Monitor Popup Count Changes

vb
Private WithEvents Toast As cToast

Private Sub Form_Load()
    Set Toast = New cToast
End Sub

Private Sub Toast_OnToastCountChange(ByVal TagName As String, _
                                     ByVal IsDelete As Boolean, _
                                     ByVal CurrentCount As Long)
    If IsDelete Then
        Debug.Print "Popup " & TagName & " was closed, remaining: " & CurrentCount
    Else
        Debug.Print "Popup " & TagName & " was created, total: " & CurrentCount
    End If
End Sub

33. Monitor Batch Close Event

vb
Private WithEvents Toast As cToast

Private Sub Toast_OnCloseAll(ByVal ClosedCount As Long)
    Debug.Print "Batch closed " & ClosedCount & " popups"
    
    ' Can trigger other operations
    RefreshUI
    LogStatistics ClosedCount
End Sub

34. Update UI Based on Events

vb
Private WithEvents Toast As cToast

Private Sub Toast_OnToastCountChange(ByVal TagName As String, _
                                     ByVal IsDelete As Boolean, _
                                     ByVal CurrentCount As Long)
    ' Update UI control
    lblToastCount.Caption = "Current: " & CurrentCount
    
    ' Refresh popup list
    RefreshPopupList
End Sub

Private Sub RefreshPopupList()
    Dim Keys As Collection
    Dim Key As Variant
    
    lstToasts.Clear
    
    Set Keys = Toast.ActiveKeys
    
    If Keys.Count > 0 Then
        For Each Key In Keys
            lstToasts.AddItem CStr(Key)
        Next Key
    Else
        lstToasts.AddItem "(No active popups)"
    End If
End Sub

Real-world Scenarios

35. File Download Progress Notification

vb
Private Sub NotifyDownloadProgress(ByVal FileName As String, ByVal Progress As Long)
    Dim TagName As String
    TagName = "download_" & FileName
    
    With New cToast
        .Pos(RightBottom).Tag(TagName) _
            .State(Info) _
            .Show "Downloading: " & FileName & vbCrLf & "Progress: " & Progress & "%", _
                  0, "Download"
    End With
End Sub

' Complete download
Private Sub NotifyDownloadComplete(ByVal FileName As String)
    Dim TagName As String
    TagName = "download_" & FileName
    
    Dim Toast As New cToast
    Toast.CloseMe TagName
    
    ' Show completion notification
    With New cToast
        .Pos(RightBottom).State(Success) _
            .Show FileName & " download complete!", 3000, "Download Complete"
    End With
End Sub

36. Form Validation Error Notification

vb
Private Sub ValidateForm() As Boolean
    Dim hasError As Boolean
    hasError = False
    
    If txtName.Text = "" Then
        With New cToast
            .Pos(RightTop).State(Danger) _
                .Show "Please enter name", 3000, "Validation Error"
        End With
        hasError = True
    End If
    
    If txtEmail.Text = "" Then
        With New cToast
            .Pos(RightTop).State(Danger) _
                .Show "Please enter email", 3000, "Validation Error"
        End With
        hasError = True
    End If
    
    ValidateForm = Not hasError
End Sub

37. Database Operation Notification

vb
Private Sub SaveToDatabase()
    On Error GoTo ErrorHandler
    
    ' Simulate database operation
    ' ... database save code ...
    
    ' Success notification
    With New cToast
        .Pos(Center).State(Success) _
            .Show "Data saved successfully!", 2000, "Success"
    End With
    
    Exit Sub
    
ErrorHandler:
    ' Error notification
    With New cToast
        .Pos(Center).State(Danger) _
            .Show "Failed to save data: " & Err.Description, 5000, "Error"
    End With
End Sub

38. Network Request Notification

vb
Private Sub MakeAPIRequest()
    Dim Toast As New cToast
    
    ' Show loading notification
    Toast.Tag("api_loading").Pos(Center).State(Info) _
        .Show "Sending request, please wait...", 0, "Request"
    
    ' Simulate API request
    ' ... API call code ...
    
    ' Close loading
    Toast.CloseMe "api_loading"
    
    ' Show result
    With New cToast
        .Pos(RightTop).State(Success) _
            .Show "Request successful!", 2000, "API"
    End With
End Sub

39. Background Task Notification

vb
Private Sub BackgroundTaskProgress()
    Dim i As Integer
    Dim Toast As New cToast
    
    Toast.Pos(RightBottom).Tag("bg_task")
    
    For i = 1 To 10
        ' Update progress
        Toast.CloseMe "bg_task"
        Toast.State(Info).Show "Processing: " & (i * 10) & "%", 0, "Background Task"
        
        ' Simulate work
        DoEvents
        Sleep 500
    Next i
    
    ' Complete
    Toast.CloseMe "bg_task"
    With New cToast
        .State(Success).Show "Task complete!", 2000, "Background Task"
    End With
End Sub

40. System Maintenance Notification

vb
Private Sub ShowMaintenanceNotice()
    With New cToast
        .Pos(Center).State(Warning).Theme(Dark) _
            .Show "System will undergo maintenance at 22:00 tonight." & vbCrLf & _
                  "Please save your work.", 0, "System Notice"
    End With
End Sub

41. User Login Notification

vb
Private Sub HandleLoginSuccess(ByVal UserName As String)
    With New cToast
        .Pos(RightTop).State(Success) _
            .Show "Welcome back, " & UserName & "!", 3000, "Login"
    End With
End Sub

Private Sub HandleLoginFailure()
    With New cToast
        .Pos(RightTop).State(Danger) _
            .Show "Login failed, please check username and password", 3000, "Login Failed"
    End With
End Sub

42. Multi-Language Notification

vb
Private Sub ShowNotification(ByVal Lang As String)
    Dim msg As String
    Dim title As String
    
    If Lang = "zh" Then
        msg = "操作成功完成"
        title = "提示"
    ElseIf Lang = "en" Then
        msg = "Operation completed successfully"
        title = "Notice"
    Else
        msg = "操作成功完成"
        title = "提示"
    End If
    
    With New cToast
        .Pos(RightTop).State(Success).Show msg, 2000, title
    End With
End Sub

Best Practices

1. Choose Appropriate Positions

vb
' Tips: Use different positions for different scenarios

' Important notifications: Center
With New cToast
    .Pos(Center).State(Danger).Show "Critical error!", 0, "Important"
End With

' Success notifications: Right-top
With New cToast
    .Pos(RightTop).State(Success).Show "Saved successfully", 2000
End With

' System notifications: Bottom-center
With New cToast
    .Pos(CenterBottom).State(Info).Show "System update available", 0
End With

2. Reasonable Duration Settings

vb
' Quick notification: 1-2 seconds
With New cToast
    .State(Success).Show "Quick notification", 1000
End With

' Normal notification: 2-3 seconds
With New cToast
    .State(Info).Show "Normal notification", 2000
End With

' Important notification: 5 seconds
With New cToast
    .State(Warning).Show "Important notification", 5000
End With

' Critical notification: No auto-close
With New cToast
    .State(Danger).Show "Critical notification, user must acknowledge", 0
End With

3. Proper Resource Management

vb
Private Sub ProperToastUsage()
    Dim Toast As New cToast
    
    ' Use Toast
    
    ' Release resources promptly
    Set Toast = Nothing
End Sub

4. Use Global Singleton for Quick Notifications

vb
' Quick notification anywhere
VBMAN.Toast.State(Success).Show "Operation complete", 2000

5. Avoid Popup Overload

vb
' Bad practice: Too many notifications
For i = 1 To 50
    VBMAN.Toast.Show "Message " & i
Next i

' Good practice: Batch notification or limit quantity
With New cToast
    .Show "50 operations completed", 2000
End With

6. Use Appropriate State Colors

vb
' Information: Blue
.State(Info).Show "System information", 2000

' Success: Green
.State(Success).Show "Operation successful", 2000

' Warning: Yellow
.State(Warning).Show "Disk space low", 2000

' Error: Red
.State(Danger).Show "Operation failed", 2000

7. Clear and Concise Content

vb
' Bad: Too long
.Show "This is a very long message that users may not have time to read completely", 2000

' Good: Concise
.Show "Operation successful", 2000

8. Provide Meaningful Titles

vb
' Bad: No title
.Show "Operation failed", 2000, ""

' Good: Clear title
.Show "Operation failed", 2000, "Error"

9. Use Hover Pause Effect

vb
' Users can hover to extend viewing time
.Show "This message will pause on hover", 2000

10. Event-Driven UI Updates

vb
Private WithEvents Toast As cToast

Private Sub Toast_OnToastCountChange(ByVal TagName As String, _
                                     ByVal IsDelete As Boolean, _
                                     ByVal CurrentCount As Long)
    ' Automatically update UI
    UpdateToastCountDisplay CurrentCount
End Sub

VB6 and LOGO copyright of Microsoft Corporation