/// <summary>
 /// Hides the alerting message.
 /// </summary>
 /// <param name="task">A task to execute on the UI thread after the message is hidden.</param>
 /// <param name="parameters">The task parameters.</param>
 protected void HideMessage(NotificationTaskAction task = null, object[] parameters = null)
 {
     // Execute the code on the UI thread.
     this.Invoke(() =>
         {
             // Hide the message.
             this.notification.Hide();
             // Execute the task on the UI thread.
             if (task != null) task(parameters);
         });
 }
        // Public methods.
        /// <summary>
        /// Shows the notification form. The method is thread-safe.
        /// </summary>
        /// <param name="owner">The owner control.</param>
        /// <param name="image">The image.</param>
        /// <param name="title">The title.</param>
        /// <param name="text">The text.</param>
        /// <param name="progress">The visibility of the progress bar.</param>
        /// <param name="duration">The duration of the message in milliseconds. If negative, the message will be displayed indefinitely.</param>
        /// <param name="task">A task to execute on the UI thread before the message is shown.</param>
        /// <param name="parameters">The task parameters.</param>
        /// <returns>The dialog result.</returns>
        public DialogResult ShowDialog(
			IWin32Window owner,
			Image image,
			string title,
			string text,
			bool progress,
			int duration = -1,
			NotificationTaskAction task = null,
			object[] parameters = null)
        {
            // Set the message box parameters.
            this.image = image;
            this.title = title;
            this.Text = text;
            this.progressBar.Visible = progress;
            this.button.Visible = progress;
            this.button.Enabled = true;
            this.task = task;
            this.parameters = parameters;

            // If the duration is positive.
            if (duration > 0)
            {
                // Set the timer interval.
                this.timer.Interval = duration;
                // Enable the timer.
                this.timer.Enabled = true;
            }
            else
            {
                // Execute the task.
                if (this.task != null) this.task(this.parameters);
            }

            // Call the form opened
            this.OnFormOpened();

            // Show the control.
            return this.ShowDialog(owner);
        }
        // Protected methods.
        /// <summary>
        /// Shows an alerting message on top of the control.
        /// </summary>
        /// <param name="image">The message icon.</param>
        /// <param name="title">The message title.</param>
        /// <param name="text">The message text.</param>
        /// <param name="progress">The visibility of the progress bar.</param>
        /// <param name="duration">The duration of the message in milliseconds. If negative, the message will be displayed indefinitely.</param>
        /// <param name="task">A task to execute on the UI thread before the message is shown.</param>
        /// <param name="parameters">The task parameters.</param>
        protected void ShowMessage(
			Image image,
			string title,
			string text,
			bool progress = true,
			int duration = -1,
			NotificationTaskAction task = null,
			object[] parameters = null)
        {
            // Execute the code on the UI thread.
            this.Invoke(() =>
                {
                    // Set the message on top of all other controls.
                    this.Controls.SetChildIndex(this.notification, 0);
                    // Show the message.
                    this.notification.Show(image, title, text, progress, duration, task, parameters);
                });
        }
        /// <summary>
        /// Shows the message control. The method is thread-safe.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="title">The title.</param>
        /// <param name="text">The text.</param>
        /// <param name="progress">The visibility of the progress bar.</param>
        /// <param name="duration">The duration of the message in milliseconds. If negative, the message will be displayed indefinitely.</param>
        /// <param name="task">A task to execute on the UI thread before the message is shown.</param>
        public void Show(
			Image image,
			string title,
			string text,
			bool progress,
			int duration = -1,
			NotificationTaskAction task = null,
			object[] parameters = null)
        {
            // Set the message box parameters.
            this.image = image;
            this.title = title;
            this.Text = text;
            this.progressBar.Visible = progress;
            this.task = task;
            this.parameters = parameters;

            // Reposition the control.
            this.Reposition(progress);

            // If the duration is positive.
            if (duration > 0)
            {
                // Set the timer interval.
                this.timer.Interval = duration;
                // Enable the timer.
                this.timer.Enabled = true;
            }
            else
            {
                // Execute the task.
                if (this.task != null) this.task(this.parameters);
            }
            // Show the control.
            this.Show();
            // Refresh the control.
            this.OnRefresh();
        }