Exemple #1
0
        /// <summary>
        /// 构造一个加载遮罩层
        /// </summary>
        /// <param name="rectLayer">遮罩层坐标及尺寸</param>
        /// <param name="opacity">由一个0~1的double值表示的透明度</param>
        /// <param name="progressBar">
        /// 指示遮罩层是否包含一个进度条,在另一线程中调用 <see cref="UpdateProgress"/>更新进度条
        /// </param>
        /// <param name="customCursor">指定自定义的光标</param>
        /// <param name="newUiThread">指示遮罩层是否在独立的UI线程执行</param>
        public LoadingLayer(
            Rectangle rectLayer,
            double opacity      = .5D,
            bool progressBar    = false,
            Cursor customCursor = null,
            bool newUiThread    = false)
        {
            if (newUiThread)
            {
                _formThread = new Thread(() =>
                {
                    CreateForm(rectLayer, opacity, progressBar, customCursor);
                    _circle.Switch();
                    _form.TopMost = true;
                    Application.Run(_form);
                })
                {
                    IsBackground = true
                };
                _formThread.SetApartmentState(ApartmentState.STA);

                return;
            }

            CreateForm(rectLayer, opacity, progressBar, customCursor);
        }
Exemple #2
0
 /// <summary>
 /// 显示遮罩层,此方法将阻塞当前调用线程,
 /// 调用前请确保在另一线程中调用了Close()
 /// </summary>
 public void Show()
 {
     if (_form.InvokeRequired)
     {
         _form.BeginInvoke(new MethodInvoker(() =>
         {
             _circle.Switch();
             _form.ShowDialog();
         }));
     }
     else
     {
         _circle.Switch();
         _form.ShowDialog();
     }
 }