- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
- [VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App
[DEVEXPRESS] Hướng dẫn thêm Button và Control vào Toast Notification Manager C#
Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách thêm button và show form data và get giá trị từ Toast Notification Manager Devexpress C#.
Trong bài viết trước, mình cũng đã có bài hướng dẫn hiển thị thông báo Notification trên Windows 10.
Tuy nhiên, bài này mình sẽ hướng dẫn nâng cao thêm một tí, là cách hiển thị form trên notification và thêm button: send, dissmiss.
Khi bấm vào nút Send thì data sẽ lấy data từ thông báo notification về Winform.
Dưới đây là giao diện demo Toast Notification Manager Devexpress c#:
Source code Toast Notification Devexpress C#:
using DevExpress.XtraBars.ToastNotifications;
using SimpleBroker;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace Notification
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
toastNotificationsManager1.RegisterApplicationActivator(typeof(ToastNotificationActivatorCustom));
this.FormClosed += XtraForm1_FormClosed;
Load += Frm_Main_Load;
Closed += Form_Main_Closed;
}
private void Form_Main_Closed(object sender, EventArgs e) => this.Unsubscribe<Message>();
private void Frm_Main_Load(object sender, EventArgs e) => this.Subscribe<Message>(OnNext);
private void OnNext(Message value)
{
richTextBox1.BeginInvoke(new Action(() =>
{
richTextBox1.Text += "=============================================================" + Environment.NewLine;
richTextBox1.Text += $"{value.Data}";
richTextBox1.Text += "=============================================================" + Environment.NewLine;
}));
}
private void XtraForm1_FormClosed(object sender, FormClosedEventArgs e)
{
toastNotificationsManager1.UnregisterApplicationActivator();
}
private void button1_Click(object sender, EventArgs e)
{
toastNotificationsManager1.ShowNotification(toastNotificationsManager1.Notifications[0]);
}
private void toastNotificationsManager1_UpdateToastContent(object sender, DevExpress.XtraBars.ToastNotifications.UpdateToastContentEventArgs e)
{
XmlDocument content = e.ToastContent;
XmlElement toastElement = content.GetElementsByTagName("toast").OfType<XmlElement>().FirstOrDefault();
toastElement.SetAttribute("launch", "performAction");
XmlElement actions = content.CreateElement("actions");
toastElement.AppendChild(actions);
XmlElement text = content.CreateElement("input");
XmlElement text2 = content.CreateElement("input");
//Input Box
actions.AppendChild(text);
text.SetAttribute("id", "FirstName");
text.SetAttribute("type", "text");
text.SetAttribute("placeHolderContent", "Enter a First Name");
//Input Box
actions.AppendChild(text2);
text2.SetAttribute("id", "LastName");
text2.SetAttribute("type", "text");
text2.SetAttribute("placeHolderContent", "Type a Last Name");
//Time selector
XmlElement input = content.CreateElement("input");
actions.AppendChild(input);
input.SetAttribute("id", "Age");
input.SetAttribute("type", "selection");
input.SetAttribute("defaultInput", "18Age");
XmlElement selection = content.CreateElement("selection");
input.AppendChild(selection);
selection.SetAttribute("id", "18Age");
selection.SetAttribute("content", "18 Age");
selection = content.CreateElement("selection");
input.AppendChild(selection);
selection.SetAttribute("id", "20Age");
selection.SetAttribute("content", "20 Age");
XmlElement action = content.CreateElement("action");
//Send button
actions.AppendChild(action);
action.SetAttribute("content", "Send");
action.SetAttribute("arguments", "Send");
//Close button
action = content.CreateElement("action");
actions.AppendChild(action);
action.SetAttribute("content", "Close");
action.SetAttribute("arguments", "lose");
}
}
[Guid("faf7a0e2-d33b-46fb-8b40-6eb35e31192a"), ComVisible(true)]
public class ToastNotificationActivatorCustom : DevExpress.XtraBars.ToastNotifications.ToastNotificationActivator
{
public override void OnActivate(string arguments, Dictionary<string, string> data)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(arguments);
foreach (string key in data.Keys)
{
sb.AppendLine(string.Format("{0} = {1}", key, data[key]));
}
// MessageBox.Show(sb.ToString());
var message = new Message
{
Data = sb.ToString()
};
message.Publish();
}
}
public class Message
{
public string Data { get; set; }
}
}
Thanks for watching!