- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
- [C#] Flash Window in Taskbar Winform
- Download và Giải nén tập tin File sử dụng Powershell
- [C#] Hướng dẫn cách lấy thông tin đăng nhập tài khoản và mật khẩu web browser trên windows
- [VB.NET] CRUD Thêm xóa sửa tìm kiếm Realtime FireBase
- [C#] Hiển thị thông báo Toast Message trong lập trình Winform
- [C#] Cấu hình định dạng ngày tháng, thời gian trên Windows cho ứng dụng Winform
- [C#] Rút gọn đường dẫn link url với TinyURL API
- [C#] Hướng dẫn cách bo tròn winform with Radius
- [C#] Chia sẽ class BackGroundOverlay Show Modal cho Winform
- [C#] Hướng dẫn Flip Image Winform
- [C#] Invoke là gì? cách sử dụng phương thức Invoke()
- [C#] Hướng dẫn chia sẽ file, folder từ ứng dụng sang Zalo Chat
[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!