AlertControl警示控件——如QQ右下角弹出消息提示,过一段时间消失

AlertControl Class

The component that supports displaying alert windows.

Namespace: DevExpress.XtraBars.Alerter
Assembly: DevExpress.XtraBars.v14.1.dll

在应用程序中显示警告窗口。
 警告窗口是一个小窗,一般用来显示很短时间,时间到达后自动关闭. 是一种通知窗口,在  Microsoft Outlook里有实现.

 alert window 可以通过 Show 方法创建 使用此方法,可以指定窗口标题、文本、图像,而且可以通过tag标签给窗体管理相关数据. 之后你可以在处理鼠标或其他alert windows事件中使用这些自定义数据.

See  Alert Windows Overview  to learn more.
Example

默认情况,警示窗口是半透明的. 以下代码将使窗体不透明. 改变不透明度OpacityLevel(double 0-1,0为透明,1为不透明),处理 BeforeFormShow 事件.

C#
VB
private void alertControl1_BeforeFormShow(object sender, 
  DevExpress.XtraBars.Alerter.AlertFormEventArgs e) {
    e.AlertForm.OpacityLevel = 1;            
}


Examples

Example 1:

新建一窗体项目,从工具箱的Navigation&Layout拖动AlertControl到窗体,AlertControl在窗体中是不可见的(应该说是组件),会显示在Form下方。在AlertControl的属性中选择Buttons,添加Button集合,设置相应Button的属性。

Button图像可以通过Image属性添加图像,可以设置Button是普通按钮还是有Check状态的按钮,这个通过Behavior的Style=CheckButton设置。

还可以给按钮添加提示信息,通话Hint=text;来设置。


下面添加事件

第一个按钮为常规按钮, 单击触发 ButtonClick 事件. 第二个按钮有选中和未选中状态. 单击触发 ButtonDownChanged 事件.

在AlertControl的Events中添加事件处理代码。

AutoFormDelay属性用来设置AlertWindow窗体延迟(即每一个AlertWindow显示的时间,时间到达后会自动消失),单位:毫秒,默认7000ms,即7s

FormDisplaySpeed属性用来设置AlertWindow窗口显示速度

FormMaxCount数值用来设置AlertControl一次最多同时显示多少个Window,为0则不限制。

FormLocation用来设置AlertWindow显示的位置(相对于整个屏幕),默认为屏幕右下角BottomRight

其中PinButton、CloseButton所在位置为ControlBoxPosition,可以在顶部或右侧。

还可以添加Info的Caption、Text或Image被单击时的处理事件,方法是在

 private void alertControl1_AlertClick(object sender, DevExpress.XtraBars.Alerter.AlertClickEventArgs e)
        {
            MessageBox.Show(e.Info.Text);
        }

中获取e.Info的信息。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace RibbonApp.控件Samples
{
    public partial class AlertControlForm : Form
    {
        public AlertControlForm()
        {
            InitializeComponent();
        }


        private void alertControl1_BeforeFormShow(object sender, DevExpress.XtraBars.Alerter.AlertFormEventArgs e)
        {
            e.AlertForm.OpacityLevel = 1;
        }


        private void alertControl1_ButtonClick(object sender, DevExpress.XtraBars.Alerter.AlertButtonClickEventArgs e)
        {
            if (e.ButtonName == "alertButton1")
            {
            }
            
        }


        private void alertControl1_ButtonDownChanged(object sender, DevExpress.XtraBars.Alerter.AlertButtonDownChangedEventArgs e)
        {
            if (e.ButtonName == "alertButton2")
            {
            }
        }


        private void btnShowAlertWindow_Click(object sender, EventArgs e)
        {
            DevExpress.XtraBars.Alerter.AlertInfo info = new DevExpress.XtraBars.Alerter.AlertInfo("标题", "这里是警示信息");
          
            alertControl1.Show(this,info);
           
        }


        private void alertControl1_AlertClick(object sender, DevExpress.XtraBars.Alerter.AlertClickEventArgs e)
        {
            MessageBox.Show(e.Info.Text);
        }
    }
}


Example2:原参考文档:

下面展示如何给AlertControl.添加自定义按钮。

假定 AlertControl 控件已经放置在Form上. 本例中,两个自定义按钮将被添加到控件的 Buttons collection. 第一个按钮为常规按钮, 单击触发 ButtonClick 事件. 第二个按钮有选中和未选中状态. 单击触发 ButtonDownChanged 事件.

效果如下The result is shown below:

C#
VB
using DevExpress.XtraBars.Alerter;

// Create a regular custom button.
AlertButton btn1 = new AlertButton(Image.FromFile(@"c:\folder-16x16.png"));
btn1.Hint = "Open file";
btn1.Name = "buttonOpen";
// Create a check custom button.
AlertButton btn2 = new AlertButton(Image.FromFile(@"c:\clock-16x16.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") {
        //...
    }
}


Inheritance Hierarchy

System.Object
    System.MarshalByRefObject
       System.ComponentModel.Component
          AlertControl

See Also
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值