Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9867 for trunk/sources


Ignore:
Timestamp:
08/07/13 15:36:28 (11 years ago)
Author:
jkarder
Message:

#1042: refactored ProgressView

File:
1 edited

Legend:

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

    r9865 r9867  
    2929  public partial class ProgressView : AsynchronousContentView {
    3030    private const int DefaultCancelTimeoutMs = 3000;
    31     private readonly IView parentView;
     31    private readonly IView view;
    3232
    3333    [Category("Custom"), Description("The time that the process is allowed to exit.")]
     
    4242
    4343    private Control Control {
    44       get { return (Control)parentView; }
     44      get { return (Control)view; }
    4545    }
    4646
    4747    public bool DisposeOnFinish { get; set; }
    4848
    49     public ProgressView() {
     49    public ProgressView(IView view) {
    5050      InitializeComponent();
    51     }
    52     public ProgressView(IProgress progress)
    53       : this() {
     51      if (view == null) throw new ArgumentNullException("view", "The view is null.");
     52      if (!(view is Control)) throw new ArgumentException("The view is not a control.", "view");
     53      this.view = view;
     54    }
     55    public ProgressView(IView view, IProgress progress)
     56      : this(view) {
    5457      Content = progress;
    5558    }
    56     public ProgressView(IView parentView)
    57       : this() {
    58       if (parentView == null) throw new ArgumentNullException("parentView", "The parent view is null.");
    59       if (!(parentView is Control)) throw new ArgumentException("The parent view is not a control.", "parentView");
    60       this.parentView = parentView;
    61     }
    62     public ProgressView(IView parentView, IProgress progress)
    63       : this(parentView) {
    64       Content = progress;
    65     }
    66 
    67     public static ProgressView Attach(IView parentView, IProgress progress, bool disposeOnFinish = false) {
    68       return new ProgressView(parentView, progress) {
     59
     60    public static ProgressView Attach(IView view, IProgress progress, bool disposeOnFinish = false) {
     61      return new ProgressView(view, progress) {
    6962        DisposeOnFinish = disposeOnFinish
    7063      };
     
    10699      if (InvokeRequired) Invoke((Action)ShowProgress);
    107100      else {
    108         if (parentView != null) {
    109           this.Left = (Control.ClientRectangle.Width / 2) - (this.Width / 2);
    110           this.Top = (Control.ClientRectangle.Height / 2) - (this.Height / 2);
    111           this.Anchor = AnchorStyles.None;
     101        if (view != null) {
     102          Left = (Control.ClientRectangle.Width / 2) - (Width / 2);
     103          Top = (Control.ClientRectangle.Height / 2) - (Height / 2);
     104          Anchor = AnchorStyles.None;
    112105
    113106          LockBackground();
    114 
    115           if (!Control.Controls.Contains(this))
    116             Control.Controls.Add(this);
    117 
     107          Parent = Control.Parent;
    118108          BringToFront();
    119109        }
     
    127117      if (InvokeRequired) Invoke((Action)HideProgress);
    128118      else {
    129         if (parentView != null) {
    130           if (Control.Controls.Contains(this))
    131             Control.Controls.Remove(this);
    132 
     119        if (view != null) {
     120          Parent = null;
    133121          UnlockBackground();
    134122        }
     
    164152
    165153    private void LockBackground() {
    166       if (InvokeRequired) {
    167         Invoke((Action)LockBackground);
    168       } else {
    169         foreach (Control c in Control.Controls)
    170           c.Enabled = false;
    171         Enabled = true;
     154      if (InvokeRequired) Invoke((Action)LockBackground);
     155      else {
     156        view.Enabled = false;
    172157      }
    173158    }
     
    176161      if (InvokeRequired) Invoke((Action)UnlockBackground);
    177162      else {
    178         foreach (Control c in Control.Controls)
    179           c.Enabled = true;
    180         Enabled = false;
     163        view.Enabled = true;
    181164      }
    182165    }
Note: See TracChangeset for help on using the changeset viewer.