示例#1
0
        /// <summary>
        ///     Start the action on a separate thread and show a progress bar. When action completes the dialog is closed.
        /// </summary>
        /// <param name="owner">Parent form</param>
        /// <param name="title">Title of the window</param>
        /// <param name="action">Action to perform while displaying the dialog</param>
        /// <param name="offset">Offset from the alignment point</param>
        /// <param name="ownerAlignment">Alignment point to the parent</param>
        public static LoadingDialog Show(Form owner, string title, Action <LoadingDialogInterface> action,
                                         Point offset = default(Point), ContentAlignment ownerAlignment = ContentAlignment.MiddleCenter)
        {
            if (owner == null)
            {
                owner = DefaultOwner;
            }
            // Find the topmost form so clicking on forms above owner doesn't bring the loading form under the others
            while (owner != null && owner.OwnedForms.Length > 0)
            {
                owner = owner.OwnedForms[0];
            }

            var loadBar = new LoadingDialog(title, action)
            {
                _offset             = offset,
                _ownerAlignment     = ownerAlignment,
                Owner               = owner,
                StartPosition       = FormStartPosition.Manual,
                _startAutomatically = false,
            };

            loadBar.Show(loadBar.Owner);
            return(loadBar);
        }
示例#2
0
 internal LoadingDialogInterface(LoadingDialog dialog)
 {
     Dialog       = dialog;
     _updateTimer = new Timer
     {
         AutoReset           = true,
         Interval            = 35,
         SynchronizingObject = Dialog
     };
     _updateTimer.Elapsed += UpdateTimerOnElapsed;
     _updateTimer.Start();
 }
示例#3
0
 /// <summary>
 ///     Start the action on a separate thread and show a progress bar.
 /// </summary>
 /// <param name="owner">Parent form</param>
 /// <param name="title">Title of the window</param>
 /// <param name="action">Action to perform while displaying the dialog</param>
 /// <param name="offset">Offset from the alignment point</param>
 /// <param name="ownerAlignment">Alignment point to the parent</param>
 public static Exception ShowDialog(Form owner, string title, Action <LoadingDialogInterface> action,
                                    Point offset = default(Point), ContentAlignment ownerAlignment = ContentAlignment.MiddleCenter)
 {
     using (var loadBar = new LoadingDialog(title, action)
     {
         _offset = offset,
         _ownerAlignment = ownerAlignment,
         Owner = owner ?? DefaultOwner,
         StartPosition = FormStartPosition.Manual,
         _startAutomatically = true
     })
     {
         loadBar.ShowDialog(loadBar.Owner);
         return(loadBar.Error);
     }
 }