Changeset 17456 for branches/3040_VectorBasedGP/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs
- Timestamp:
- 02/28/20 10:43:50 (5 years ago)
- Location:
- branches/3040_VectorBasedGP
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP
- Property svn:mergeinfo changed
/trunk (added) merged: 17376-17378,17380,17384-17386,17402,17413,17421-17423,17426-17428,17430,17437,17441,17445,17450
- Property svn:mergeinfo changed
-
branches/3040_VectorBasedGP/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs
r17180 r17456 25 25 namespace HeuristicLab.MainForm.WindowsForms { 26 26 internal sealed partial class ProgressView : UserControl { 27 private readonly Control control; 28 public Control Control { 29 get { return control; } 30 } 31 32 private readonly IProgress content; 33 public IProgress Content { 34 get { return content; } 35 } 36 37 public ProgressView(Control control, IProgress content) 27 public Control TargetControl { get; } 28 public IProgress Content { get; } 29 30 public ProgressView(Control targetControl, IProgress content) 38 31 : base() { 39 if ( control == null) throw new ArgumentNullException("control");40 if ( control.Parent == null) throw new InvalidOperationException("A Progress can only be shown on controls that have a Parent-control. Therefore, Dialogs and Forms cannot have an associated ProgressView.");41 if (content == null) throw new ArgumentNullException( "content");32 if (targetControl == null) throw new ArgumentNullException(nameof(targetControl)); 33 if (targetControl.Parent == null) throw new InvalidOperationException("A Progress can only be shown on controls that have a Parent-control. Therefore, Dialogs and Forms cannot have an associated ProgressView."); 34 if (content == null) throw new ArgumentNullException(nameof(content)); 42 35 InitializeComponent(); 43 36 44 this. control = control;45 this. content = content;37 this.TargetControl = targetControl; 38 this.Content = content; 46 39 47 40 if (content.ProgressState != ProgressState.Finished) … … 52 45 protected override void Dispose(bool disposing) { 53 46 DeregisterContentEvents(); 54 HideProgress(); 55 56 if (disposing && (components != null)) { 47 48 if (!TargetControl.IsDisposed) 49 HideProgress(); 50 51 if (disposing && components != null) { 57 52 components.Dispose(); 58 53 } … … 101 96 102 97 private void ShowProgress() { 103 if ( Control.InvokeRequired) {104 Control.Invoke((Action)ShowProgress);98 if (TargetControl.InvokeRequired) { 99 TargetControl.Invoke((Action)ShowProgress); 105 100 return; 106 101 } 107 102 if (Parent != null) return; 108 103 109 Left = ( Control.ClientRectangle.Width / 2) - (Width / 2);110 Top = ( Control.ClientRectangle.Height / 2) - (Height / 2);104 Left = (TargetControl.ClientRectangle.Width / 2) - (Width / 2); 105 Top = (TargetControl.ClientRectangle.Height / 2) - (Height / 2); 111 106 Anchor = AnchorStyles.None; 112 107 … … 115 110 UpdateButtonsState(); 116 111 117 Control.SuspendRepaint(); 118 Control.Enabled = false; 119 Parent = Control.Parent; 112 TargetControl.SuspendRepaint(); 113 TargetControl.Enabled = false; 114 RegisterTargetControlEvents(); 115 Parent = TargetControl.Parent; 120 116 BringToFront(); 121 Control.ResumeRepaint(true);117 TargetControl.ResumeRepaint(true); 122 118 Visible = true; 123 119 } 124 120 125 121 private void HideProgress() { 126 if ( Control.InvokeRequired) {127 Control.Invoke((Action)HideProgress);122 if (TargetControl.InvokeRequired) { 123 TargetControl.Invoke((Action)HideProgress); 128 124 return; 129 125 } … … 131 127 132 128 Visible = false; 133 Control.SuspendRepaint();134 Control.Enabled = true;135 Control.ResumeRepaint(true);129 TargetControl.SuspendRepaint(); 130 TargetControl.Enabled = true; 131 DeregisterTargetControlEvents(); 136 132 Parent = null; 133 TargetControl.ResumeRepaint(TargetControl.Visible); 134 } 135 136 137 private void RegisterTargetControlEvents() { 138 TargetControl.Disposed += TargetControl_Disposed; 139 TargetControl.VisibleChanged += TargetControl_VisibleChanged; 140 TargetControl.ParentChanged += TargetControl_ParentChanged; 141 } 142 143 private void DeregisterTargetControlEvents() { 144 TargetControl.Disposed -= TargetControl_Disposed; 145 TargetControl.VisibleChanged -= TargetControl_VisibleChanged; 146 TargetControl.ParentChanged -= TargetControl_ParentChanged; 147 } 148 149 private void TargetControl_Disposed(object sender, EventArgs e) { 150 Dispose(); 151 } 152 private void TargetControl_VisibleChanged(object sender, EventArgs e) { 153 Visible = TargetControl.Visible; 154 } 155 private void TargetControl_ParentChanged(object sender, EventArgs e) { 156 Parent = TargetControl.Parent; 137 157 } 138 158 139 159 private void UpdateProgressState() { 140 if ( Control.InvokeRequired) {141 Control.Invoke((Action)UpdateProgressState);160 if (TargetControl.InvokeRequired) { 161 TargetControl.Invoke((Action)UpdateProgressState); 142 162 return; 143 163 } … … 150 170 151 171 private void UpdateProgressMessage() { 152 if ( Control.InvokeRequired) {153 Control.Invoke((Action)UpdateProgressMessage);154 return; 155 } 156 157 messageLabel.Text = content.Message;172 if (TargetControl.InvokeRequired) { 173 TargetControl.Invoke((Action)UpdateProgressMessage); 174 return; 175 } 176 177 messageLabel.Text = Content.Message; 158 178 } 159 179 … … 167 187 case ProgressMode.Determinate: 168 188 progressBar.Style = ProgressBarStyle.Continuous; 169 progressBar.Value = (int)Math.Round(progressBar.Minimum + content.ProgressValue * (progressBar.Maximum - progressBar.Minimum));189 progressBar.Value = (int)Math.Round(progressBar.Minimum + Content.ProgressValue * (progressBar.Maximum - progressBar.Minimum)); 170 190 break; 171 191 case ProgressMode.Indeterminate: … … 174 194 break; 175 195 default: 176 throw new NotImplementedException($"Invalid Progress Mode: { content.ProgressMode}");196 throw new NotImplementedException($"Invalid Progress Mode: {Content.ProgressMode}"); 177 197 } 178 198 } 179 199 180 200 private void UpdateButtonsState() { 181 if ( Control.InvokeRequired) {182 Control.Invoke((Action)UpdateButtonsState);201 if (TargetControl.InvokeRequired) { 202 TargetControl.Invoke((Action)UpdateButtonsState); 183 203 return; 184 204 } 185 205 186 206 stopButton.Visible = Content.CanBeStopped; 187 stopButton.Enabled = Content.CanBeStopped && content.ProgressState == ProgressState.Started;207 stopButton.Enabled = Content.CanBeStopped && Content.ProgressState == ProgressState.Started; 188 208 189 209 cancelButton.Visible = Content.CanBeCanceled; 190 cancelButton.Enabled = Content.CanBeCanceled && content.ProgressState == ProgressState.Started;210 cancelButton.Enabled = Content.CanBeCanceled && Content.ProgressState == ProgressState.Started; 191 211 } 192 212
Note: See TracChangeset
for help on using the changeset viewer.