在做倉儲管理系統時,如果倉儲物品儲量過高,給出提示,這時候可以使用Devexpress的AlertControl控件。
AutoFormDelay可以設置通知窗體顯示的時間。
AlertClick事件可以處理點擊通知窗體的操作。
具體代碼:
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
namespace NotificationApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
Message msg = new Message();
//顯示通知窗體
alertControl1.Show(this, msg.Caption, msg.Text, "", msg.Image, msg);
}
/// <summary>
/// 設置通知窗體不透明度
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void alertControl1_BeforeFormShow(object sender, DevExpress.XtraBars.Alerter.AlertFormEventArgs e)
{
e.AlertForm.OpacityLevel = 1;
}
/// <summary>
/// 處理通知窗體點擊事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void alertControl1_AlertClick(object sender, DevExpress.XtraBars.Alerter.AlertClickEventArgs e)
{
Message msg = e.Info.Tag as Message;
XtraMessageBox.Show(msg.Text, msg.Caption);
}
}
public class Message
{
public Message()
{
this.Caption = "庫存超高告警";
this.Text = "掘進一隊庫存材料-鐵杴:現有9把";
this.Image = global::NotificationApp.Properties.Resources.倉儲;
}
public string Caption { get; set; }
public string Text { get; set; }
public Image Image { get; set; }
}
}
效果: