Example #1
0
        private static void td_timer(object obj)
        {
            MBox   mbox         = obj as MBox;
            Button btn          = null;
            string btnOriginStr = "";

            mbox.Dispatcher.Invoke(new Action(delegate
            {
                if (mbox.grid_ret1.Visibility == Visibility.Visible)
                {
                    btn = mbox.btn_ret1_yes;
                }
                else if (mbox.grid_ret2.Visibility == Visibility.Visible)
                {
                    btn = mbox.btn_ret2_yes;
                }
                else if (mbox.grid_ret3.Visibility == Visibility.Visible)
                {
                    btn = mbox.btn_ret3_yes;
                }
                btnOriginStr = btn.Content.ToString();
            }));

            while (mbox._limitSec > 0)
            {
                mbox.Dispatcher.Invoke(new Action(delegate
                {
                    if (mbox.IsActive)
                    {
                        btn.Content = btnOriginStr + "(" + mbox._limitSec.ToString() + ")";
                    }
                }));

                System.Threading.Thread.Sleep(1000);
                --mbox._limitSec;
            }

            mbox.Dispatcher.Invoke(new Action(delegate
            {
                if (mbox.IsActive)
                {
                    MBox._result = MBoxResult.Yes;
                    mbox.Close();
                }
            }));
        }
Example #2
0
 private void btn_ret3_cancel_Click(object sender, RoutedEventArgs e)
 {
     _result = MBoxResult.Cancel;
     Close();
 }
Example #3
0
 private void btn_ret3_no_Click(object sender, RoutedEventArgs e)
 {
     _result = MBoxResult.No;
     Close();
 }
Example #4
0
 private void btn_ret2_yes_Click(object sender, RoutedEventArgs e)
 {
     _result = MBoxResult.Yes;
     Close();
 }
Example #5
0
        static private MBoxResult doShow(string title, Run[] contents, string[] operators, MBoxType type, int limitSec)
        {
            MBoxResult ret = MBoxResult.Yes;
            List <ContentDescription> lsContents = new List <ContentDescription>();

            foreach (var run in contents)
            {
                ContentDescription cd = new ContentDescription(run);
                lsContents.Add(cd);
            }

            Application.Current.Dispatcher.Invoke(new Action(delegate
            {
                MBox mbox = new MBox();
                mbox.setType(mbox, type);
                mbox.tbk_content.Text = "";
                mbox.tbk_head.Text    = "";

                if (title == null || contents == null || operators == null)
                {
                    mbox.ShowDialog();
                }

                if (operators.Length == 1)
                {
                    mbox.grid_ret2.Visibility = mbox.grid_ret3.Visibility = Visibility.Hidden;
                    mbox.grid_ret1.Visibility = Visibility.Visible;
                    mbox.btn_ret1_yes.Content = operators[0];
                }
                else if (operators.Length == 2)
                {
                    mbox.grid_ret1.Visibility = mbox.grid_ret3.Visibility = Visibility.Hidden;
                    mbox.grid_ret2.Visibility = Visibility.Visible;
                    mbox.btn_ret2_yes.Content = operators[0];
                    mbox.btn_ret2_no.Content  = operators[1];
                }
                else if (operators.Length == 3)
                {
                    mbox.grid_ret1.Visibility    = mbox.grid_ret2.Visibility = Visibility.Hidden;
                    mbox.grid_ret3.Visibility    = Visibility.Visible;
                    mbox.btn_ret3_yes.Content    = operators[0];
                    mbox.btn_ret3_no.Content     = operators[1];
                    mbox.btn_ret3_cancel.Content = operators[2];
                }

                mbox.tbk_head.Text = title;
                foreach (var r in lsContents)
                {
                    mbox.tbk_content.Inlines.Add(r.convertToRun());
                }

                if (limitSec > 0)
                {
                    mbox._limitSec        = limitSec;
                    WaitCallback workItem = new WaitCallback(td_timer);
                    ThreadPool.QueueUserWorkItem(workItem, mbox);
                }

                mbox.ShowDialog();
                ret = _result;
            }));

            return(ret);
        }