当前位置:   article > 正文

有关AlterControl控件的简单应用

c# altercontrol
AlertControl控件首先是用来在页面上弹出提示框的。在DevExpress.XtraBars.Alerter这个命名空间下。如果用代码来生成altercontrol控件的话,例子如下:
   
   如果我们在form窗体上直接拖一个控件过来,那么对于altercontrol控件的事件就很熟悉了;
    private void alertControl1_ButtonDownChanged(object sender, AlertButtonDownChangedEventArgs e) {
            if(e.ButtonName == "Flag") 
                ((MailData)e.Info.Tag).Flag = e.Down ? 0 : 1;
            if(e.ButtonName == "Read") 
                ((MailData)e.Info.Tag).Read = e.Down ? 1 : 0;
        }
        private void alertControl1_ButtonClick(object sender, AlertButtonClickEventArgs e) {
            MailData data = e.Info.Tag as MailData;
            e.AlertForm.OwnerForm.Activate();//激活窗体
            if(e.ButtonName == "Attachment") {
                e.AlertForm.Close();//弹出窗体关闭
                XtraMessageBox.Show(FindForm(), "Open attachment dialog.", string.Format("Mail From: {0}", data.From));
            }
            if(e.ButtonName == "Delete") 
                DeleteItem(e, data);
        }
        void OpenItem(MailData data) {
            for(int i = 0; i < gridView1.RowCount; i++) {
                if(data.Row.Equals(gridView1.GetDataRow(i))) {
                    gridView1.FocusedRowHandle = i;
                    break;
                }
            }
        }
        void DeleteItem(AlertClickEventArgs args, MailData data) {
            args.AlertForm.Close();
            try {
                DataTable tbl = gridControl1.DataSource as DataTable;
                tbl.Rows.Remove(data.Row);
                gridView1.LayoutChanged();
            }
            catch { }
        }
        private void alertControl1_AlertClick(object sender, AlertClickEventArgs e) {
            MailData data = e.Info.Tag as MailData;
            OpenItem(data);
        }
   下面看下用代码直接生成的例子:
   private IAppMain appMainCode;
   private delegate void CloseAlert(AlertControl ac);
   void createAlterControl()
  {
     AlertControl ac = new AlertControl();
     ac.ShowPinButton = true;
     ac.ShowCloseButton = true;
     ac.AlertClick += new AlertClickEventHandler(alertControl1_AlertClick);
     ac.FormLoad += alertControl1_FormLoad;
     AlertInfo info = new AlertInfo("拉停提醒", alertinfo, null, null, equ.id);
     ac.Show(appcontrol, info);
   }
        /// <summary>
        /// 点击链接弹出页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void alertControl1_AlertClick(object sender, DevExpress.XtraBars.Alerter.AlertClickEventArgs e)
        {
            CreateAlertControl cr = new CreateAlertControl();
            string menucode = GetxmlDoumentByMenuCode();//得到配置文件;
            if (!String.IsNullOrEmpty(menucode))
            {
                appMainCode.OpenApp(cr, menucode);
            }
            else
            {
                MessageBox.Show("请配置xml文件中的拉停监控的菜单编号!");
            }
        }
        /// <summary>
        /// 窗体加载时锁定页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void alertControl1_FormLoad(object sender, AlertFormLoadEventArgs e)
        {
            e.Buttons[1].OnClick();//弹出页面只放出了锁定和关闭按钮。
        }
         /// <summary>
        /// 弹出窗体关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void alertControl1_FormClose(string equid)
        {
            lock (diclst)
            {
                if (diclst != null && diclst.Count > 0)
                {
                    if (diclst.ContainsKey(equid))
                    {
                        AlertControl delete = new AlertControl();
                        delete = diclst[equid];
                        diclst.Remove(equid);
                        delete.AlertFormList[0].Invoke(new CloseAlert(AlertClose), delete);//此处由于程序运行时再辅助线程,所以需要通过Invoke回到主线程上去执行;
                    }
                }
            }
        }
        private void AlertClose(AlertControl ac)
        {
            ac.AlertFormList[0].Buttons[0].OnClick();
        }
另一方面,如果我们新建个类,类中的数据需要在别的页面调用。我们就可以通过将类实例化去得到类中的属性;
 public static CreateAlertControl Instance
        {
            get;
            set;
        }
在页面加载时赋值Instance = this;
在别的页面我们就可以通过CreateAlertControl.diclst去调用类中的属性;

转载于:https://www.cnblogs.com/xiaoxihebei/p/9336455.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/402797
推荐阅读
相关标签
  

闽ICP备14008679号