在做仓储管理系统时,如果仓储物品储量过高,给出提示,这时候可以使用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; }
}
}
效果: