Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/12 12:00:51 (12 years ago)
Author:
ascheibe
Message:

#1762 implemented review comments:

  • removed self disposing. The progress view now reacts if a progress is set and Finish() is now called on the progress object and not the view.
  • Moved Cancel event from ProgressView to Progress
  • throw ArgumentNullException if the parent view is null
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Views/ProgressView.cs

    r8135 r8145  
    3535        progress = value;
    3636        RegisterProgressEvents();
     37        ShowProgress();
    3738        OnProgressChanged();
    3839      }
     
    4849    }
    4950
    50     /// <param name="parentView">This is the view which will be locked while progress is made.</param>
    51     public ProgressView(ContentView parentView, IProgress progress) {
     51    private void ShowProgress() {
     52      this.Left = (parentView.ClientRectangle.Width / 2) - (this.Width / 2);
     53      this.Top = (parentView.ClientRectangle.Height / 2) - (this.Height / 2);
     54      this.Anchor = AnchorStyles.Left | AnchorStyles.Top;
     55
     56      LockBackground();
     57
     58      if (!parentView.Controls.Contains(this)) {
     59        parentView.Controls.Add(this);
     60      }
     61
     62      BringToFront();
     63      Visible = true;
     64    }
     65
     66    public ProgressView(ContentView parentView) {
    5267      InitializeComponent();
    53       Progress = progress;
    5468      CancelEnabled = false;
    5569
    5670      if (parentView != null) {
    5771        this.parentView = parentView;
    58         this.Left = (parentView.ClientRectangle.Width / 2) - (this.Width / 2);
    59         this.Top = (parentView.ClientRectangle.Height / 2) - (this.Height / 2);
    60         this.Anchor = AnchorStyles.Left | AnchorStyles.Top;
    61 
    62         LockBackground();
    63 
    64         parentView.Controls.Add(this);
    65         BringToFront();
     72      } else {
     73        throw new ArgumentNullException("The parent view is null.");
    6674      }
    6775    }
     
    7280      progress.StatusChanged += new EventHandler(progress_StatusChanged);
    7381      progress.ProgressValueChanged += new EventHandler(progress_ProgressValueChanged);
     82      progress.Canceled += new EventHandler(progress_Canceled);
    7483    }
    7584
     
    7988      progress.StatusChanged -= new EventHandler(progress_StatusChanged);
    8089      progress.ProgressValueChanged -= new EventHandler(progress_ProgressValueChanged);
     90      progress.Canceled -= new EventHandler(progress_Canceled);
    8191    }
    8292
     
    91101    private void progress_ProgressValueChanged(object sender, EventArgs e) {
    92102      UpdateProgressValue();
     103    }
     104
     105    void progress_Canceled(object sender, EventArgs e) {
     106      Finish();
    93107    }
    94108
     
    128142    }
    129143
    130     public void Finish() {
     144    private void Finish() {
    131145      if (InvokeRequired) {
    132146        Invoke(new Action(Finish));
     
    139153          c.Enabled = true;
    140154        DeregisterProgressEvents();
    141         Dispose();
     155        progress = null;
     156        this.Visible = false;
    142157      }
    143158    }
    144159
    145160    private void cancelButton_Click(object sender, EventArgs e) {
    146       OnCanceled();
    147       Finish();
     161      if (progress != null) {
     162        progress.CancelRequested = true;
     163        cancelButton.Enabled = false;
     164      }
    148165    }
    149166
     
    160177      UpdateProgressValue();
    161178    }
    162 
    163     public event EventHandler Canceled;
    164     protected virtual void OnCanceled() {
    165       var handler = Canceled;
    166       if (handler != null) Canceled(this, EventArgs.Empty);
    167     }
    168179  }
    169180}
Note: See TracChangeset for help on using the changeset viewer.