- [DATABASE] Hướng dẫn thêm và cập nhật Extended Property Column trong Table Sqlserver
- [DEVEXPRESS] Hướng dẫn sử dụng Vertical Gridview để hiển thị thông tin sản phẩm
- [C#] Hướng dẫn sử dụng Json Schema để Validate chuỗi string có phải json
- [C#] Hướng dẫn sử dụng công cụ Clean Code trên Visual Studio
- [C#] Hướng dẫn Drag and Drop File vào RichTextBox
- [C#] Hướng dẫn tạo hiệu ứng Karaoke Text Effect Winform
- [C#] Sử dụng thư viện ZedGraph vẽ biểu đồ Line, Bar, Pie trên Winform
- [DATABASE] Hướng dẫn sort sắp xếp địa chỉ IP trên sqlserver sử dụng hàm PARSENAME
- [C#] Theo dõi sử kiện process Start hay Stop trên Winform
- [ASP.NET] Chia sẻ source code chụp hình sử dụng camera trên website
- [C#] Chạy ứng dụng trên Virtual Desktop (màn hình ảo) Winform
- [C#] Mã hóa và giải mã Data Protection API trên winform
- [C#] Hướng dẫn tạo Gradient Background trên Winform
- [DATABASE] Hướng dẫn convert Epoch to DateTime trong sqlserver
- [DATABASE] Hướng dẫn sử dụng STRING_AGG và CONCAT_WS trong sqlserver 2017
- [C#] Hướng dẫn Copy With All Property in Class Object
- [DEVEXPRESS] Hướng dẫn load Json DataSource vào GridView
- [C#] Hướng dẫn tạo chữ ký trên winform Signature Pad
- [DEVEXPRESS] Format code T-SQL highlight in RichEditControl
- [C#] Hướng dẫn upload file, hình ảnh từ Winform lên server API ASP.NET Core
[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!