1.5 AlertControl控件
AlertControl控件能改在应用程序中显示警告窗口,
通常该警告窗口显示为: 出现在右下角的一个短的提示框并且会自动关闭,
可以在该窗口中指定标题、文本、图像,并定义相应的处理事件。
实现效果如图:
实现代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraBars.Alerter;
namespace DXApplication_1
{
public partial class AlertControlForm : DevExpress.XtraEditors.XtraForm
{
public AlertControlForm()
{
InitializeComponent();
}
private void AlertControlForm_Load(object sender, EventArgs e)
{
// Create a regular custom button.
AlertButton btn1 = new AlertButton(Image.FromFile(@"C:\\Users\\teeking_scx\\source\\repos\\DXApplication_1\\imgs\\new.png"));
btn1.Hint = "Open file";
btn1.Name = "buttonOpen";
// Create a check custom button.
AlertButton btn2 = new AlertButton(Image.FromFile(@"C:\\Users\\teeking_scx\\source\\repos\\DXApplication_1\\imgs\\heart.png"));
btn2.Style = AlertButtonStyle.CheckButton;
btn2.Down = true;
btn2.Hint = "Alert On";
btn2.Name = "buttonAlert";
// Add buttons to the AlertControl and subscribe to the events to process button clicks
alertControl1.Buttons.Add(btn1);
alertControl1.Buttons.Add(btn2);
alertControl1.ButtonClick += new AlertButtonClickEventHandler(alertControl1_ButtonClick);
alertControl1.ButtonDownChanged +=
new AlertButtonDownChangedEventHandler(alertControl1_ButtonDownChanged);
// Show a sample alert window.
AlertInfo info = new AlertInfo("New Window", "Text");
alertControl1.Show(this, info);
}
void alertControl1_ButtonDownChanged(object sender,AlertButtonDownChangedEventArgs e)
{
if (e.ButtonName == "buttonOpen")
{
}
}
void alertControl1_ButtonClick(object sender, AlertButtonClickEventArgs e)
{
if (e.ButtonName == "buttonAlert")
{
}
}
}
}