ชุมชนคนรักภาษาเบสิค - Visual Basic Community

 ลืมรหัสผ่าน
 ลงทะเบียน
ค้นหา
ดู: 580|ตอบกลับ: 0

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

[คัดลอกลิงก์]

311

กระทู้

502

โพสต์

6066

เครดิต

ผู้ดูแลระบบ

ทองก้อน ทับทิมกรอบ

Rank: 9Rank: 9Rank: 9

เครดิต
6066

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


Popup Notification using Tulpep nuget package.







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

  3. Imports Tulpep.NotificationWindow

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

  8.     Private Sub frmNotification_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  9.         '// Sub Program.
  10.         '// Image, BodyColor, TitleText, TitleColor, ContentText, ContentColor
  11.         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)
  12.     End Sub

  13.     '//
  14.     Private Sub Notification(
  15.                             ByVal img As String,
  16.                             ByVal BodyColor As System.Drawing.Color,
  17.                             ByVal TitleText As String,
  18.                             ByVal TitleColor As System.Drawing.Color,
  19.                             ByVal ContentText As String,
  20.                             ByVal ContentColor As System.Drawing.Color
  21.                             )
  22.     Dim Popup As PopupNotifier = New PopupNotifier()
  23.     Dim bitmap As Bitmap
  24.         Try
  25.             bitmap = Image.FromFile(strPathImage & img)
  26.             With Popup
  27.                 .Image = bitmap
  28.                 .BodyColor = BodyColor
  29.                 .TitleText = TitleText
  30.                 .TitleColor = TitleColor
  31.                 .TitleFont = TitleFont
  32.                 .ContentText = ContentText
  33.                 .ContentColor = ContentColor
  34.                 .ContentFont = ContentFont
  35.                 .Popup()
  36.             End With
  37.         Catch ex As Exception
  38.             MessageBox.Show(ex.Message)
  39.         End Try
  40.     End Sub

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

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

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

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

  53. #Region "Function"
  54.     ' / --------------------------------------------------------------------------------
  55.     ' / Get my project path
  56.     ' / AppPath = C:\My Project\bin\debug
  57.     ' / Replace "\bin\debug" with ""
  58.     ' / Return : C:\My Project\
  59.     Function MyPath(AppPath As String) As String
  60.         '/ MessageBox.Show(AppPath)
  61.         AppPath = AppPath.ToLower()
  62.         '/ Return Value
  63.         MyPath = AppPath.Replace("\bin\debug", "").Replace("\bin\release", "").Replace("\bin\x86\debug", "")
  64.         '// If not found folder then put the \ (BackSlash) at the end.
  65.         If Microsoft.VisualBasic.Right(MyPath, 1) <> "" Then MyPath = MyPath & ""
  66.     End Function
  67. #End Region

  68. End Class
คัดลอกไปที่คลิปบอร์ด


ดาวน์โหลดโค้ดต้นฉบับ Visual Basic .Net (2010) ได้ที่นี่ ...

ขออภัย! โพสต์นี้มีไฟล์แนบหรือรูปภาพที่ไม่ได้รับอนุญาตให้คุณเข้าถึง

คุณจำเป็นต้อง ลงชื่อเข้าใช้ เพื่อดาวน์โหลดหรือดูไฟล์แนบนี้ คุณยังไม่มีบัญชีใช่ไหม? ลงทะเบียน

x
สิ่งที่ดีกว่าการให้ คือการให้แบบไม่มีที่สิ้นสุด
ขออภัย! คุณไม่ได้รับสิทธิ์ในการดำเนินการในส่วนนี้ กรุณาเลือกอย่างใดอย่างหนึ่ง ลงชื่อเข้าใช้ | ลงทะเบียน

รายละเอียดเครดิต

ข้อความล้วน|อุปกรณ์พกพา|ประวัติการแบน|G2GNet.com  

GMT+7, 2024-5-3 02:13 , Processed in 0.274047 second(s), 4 queries , File On.

Powered by Discuz! X3.4, Rev.62

Copyright © 2001-2020 Tencent Cloud.

ตอบกระทู้ ขึ้นไปด้านบน ไปที่หน้ารายการกระทู้