- [C#] Di chuyển và thay đổi kích thước Control Winform khi ứng dụng đang chạy
- [VB.NET] Chia sẻ source tạo sắp xếp đội hình bóng đá Line-ups đội bóng
- [C#] Hướng dẫn chỉnh sửa Text của label trực tiếp trên winform
- [C#] Hướng dẫn custom TextBox giống Ultraviewer trên Winform
- [C#] Show Modal Winform like Bootstrap
- [DATABASE] Thứ tự thực hiện mệnh đề truy vấn SELECT trong Sqlserver
- [C#] Hướng dẫn viết addin Excel Lấy hình ảnh từ URL internet vào Excel
- [DATABASE] TSQL view max length all column data trên table Sqlserver
- [DEVEXPRESS] Hướng dẫn sử dụng MailMerge kèm Hình ảnh trên Winform
- [DATABASE] Hướng dẫn truy vấn xem kích thước lưu trữ của từng bảng ghi Table trên sqlserver
- [C#] Hướng dẫn Fake Date Time sử dụng thư viện Harmony
- [DATABASE] Phân biệt câu lệnh DDL và DML trong sqlserver
- [C#] Hướng dẫn convert file mã HTML sang file Pdf trên winform
- [DEVEXPRESS] Tạo các loại mã vạch Barcode trực tiếp trên Devexpress Barcode API
- [DEVEXPRESS] Hướng dẫn custom Simple button thành Progressbar
- [DATABASE] Tách số và chữ từ chuỗi - hàm tối ưu hóa tách số và chữ trong Sqlserver
- [C#] Tìm kiếm gần đúng Full Text Search sử dụng thư viện Lucene.NET
- [C#] Chia sẻ tài liệu, sdk và source code máy chấm công dòng máy ZKTeco
- [C#] Memory Cache là gì, và sử dụng trong ứng dụng Winform
- [DATABASE] Khóa chính Primary Key trong Sqlserver
[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!