thongkorn โพสต์ 2023-8-24 11:51:03

[VB.NET] การทำ Popup Notification หรือแสดงหน้าจอการแจ้งเตือน

การทำ Popup Notification หรือแสดงหน้าจอและข้อความการแจ้งเตือนแสดงผลทางด้านล่างมุมขวาสุดของจอภาพ โปรเจคนี้จะใช้ของฟรีจาก Tulpep.NotificationWindow สำหรับโค้ดตัวอย่างแอดมินจะใช้ Visual Basic .Net Framework 4.0 ซึ่งในไฟล์บีบอัด (ZIP) จะมีไฟล์ DLL มาพร้อมให้อยู่แล้ว แค่เลือก Add References เข้ามาเท่านั้น ...


Popup Notification using Tulpep nuget package.


http://www.g2gsoft.com/webboard/images/VBNet/popupnotification.png




มาดูโค้ดฉบับเต็มกันเถอะ ...
'// .Net Framework from 4.0+
'// https://www.nuget.org/packages/Tulpep.NotificationWindow

Imports Tulpep.NotificationWindow

Public Class frmNotification
    Private strPathImage = MyPath(Application.StartupPath) & "Images\"
    Dim TitleFont As New Font("Century Gothic", 15, FontStyle.Bold)
    Dim ContentFont As New Font("Century Gothic", 12, FontStyle.Regular)

    Private Sub frmNotification_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
      '// Sub Program.
      '// Image, BodyColor, TitleText, TitleColor, ContentText, ContentColor
      Call Notification("Info.png", Color.Green, "HELLO, WORLD.", Color.Black, "This is a book." & vbCrLf & "This is a chair." & vbCrLf & "I'm fine, Thank you.", Color.White)
    End Sub

    '//
    Private Sub Notification(
                            ByVal img As String,
                            ByVal BodyColor As System.Drawing.Color,
                            ByVal TitleText As String,
                            ByVal TitleColor As System.Drawing.Color,
                            ByVal ContentText As String,
                            ByVal ContentColor As System.Drawing.Color
                            )
    Dim Popup As PopupNotifier = New PopupNotifier()
    Dim bitmap As Bitmap
      Try
            bitmap = Image.FromFile(strPathImage & img)
            With Popup
                .Image = bitmap
                .BodyColor = BodyColor
                .TitleText = TitleText
                .TitleColor = TitleColor
                .TitleFont = TitleFont
                .ContentText = ContentText
                .ContentColor = ContentColor
                .ContentFont = ContentFont
                .Popup()
            End With
      Catch ex As Exception
            MessageBox.Show(ex.Message)
      End Try
    End Sub

    Private Sub btnSuccess_Click(sender As Object, e As EventArgs) Handles btnSuccess.Click
      Call Notification("Success.png", Color.FromArgb(40, 167, 69), "SUCCESS", Color.White, "Your Success Message.", Color.White)
    End Sub

    Private Sub btnInfo_Click(sender As Object, e As EventArgs) Handles btnInfo.Click
      Call Notification("Info.png", Color.FromArgb(0, 192, 192), "INFORMATION", Color.White, "Your Information Message.", Color.White)
    End Sub

    Private Sub btnWarning_Click(sender As Object, e As EventArgs) Handles btnWarning.Click
      Call Notification("Warning.png", Color.FromArgb(255, 193, 7), "WARNING", Color.Black, "Your Warning Message.", Color.Black)
    End Sub

    Private Sub btnError_Click(sender As Object, e As EventArgs) Handles btnError.Click
      Call Notification("Error.png", Color.Red, "ERROR", Color.White, "Your Warning Message.", Color.White)
    End Sub

#Region "Function"
    ' / --------------------------------------------------------------------------------
    ' / Get my project path
    ' / AppPath = C:\My Project\bin\debug
    ' / Replace "\bin\debug" with "\"
    ' / Return : C:\My Project\
    Function MyPath(AppPath As String) As String
      '/ MessageBox.Show(AppPath)
      AppPath = AppPath.ToLower()
      '/ Return Value
      MyPath = AppPath.Replace("\bin\debug", "\").Replace("\bin\release", "\").Replace("\bin\x86\debug", "\")
      '// If not found folder then put the \ (BackSlash) at the end.
      If Microsoft.VisualBasic.Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
    End Function
#End Region

End Class

ดาวน์โหลดโค้ดต้นฉบับ Visual Basic .Net (2010) ได้ที่นี่ ...
หน้า: [1]
ดูในรูปแบบกติ: [VB.NET] การทำ Popup Notification หรือแสดงหน้าจอการแจ้งเตือน