有關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 p_w_upload 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去調用類中的屬性;
相關文章
相關標籤/搜索