Ticket #2978: CountViewEvents.patch
File CountViewEvents.patch, 5.3 KB (added by gkronber, 6 years ago) |
---|
-
View.cs
20 20 #endregion 21 21 22 22 using System; 23 using System.Diagnostics; 24 using System.Drawing; 23 25 using System.Linq; 24 26 using System.Reflection; 25 27 using System.Windows.Forms; … … 27 29 namespace HeuristicLab.MainForm.WindowsForms { 28 30 public partial class View : UserControl, IView { 29 31 private bool initialized; 32 public int[] counters = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 30 33 public View() { 31 34 InitializeComponent(); 35 label.Paint += Label_Paint; 36 32 37 this.initialized = false; 33 38 this.isShown = false; 34 39 this.closeReason = CloseReason.None; … … 37 42 this.Caption = ViewAttribute.GetViewName(this.GetType()); 38 43 else 39 44 this.Caption = "View"; 45 if (this is ViewHost) { 46 label.Location = new Point(0, 0); 47 } else { 48 label.Location = new Point(0, 15); 49 } 50 label.BringToFront(); 40 51 } 41 52 42 53 private string caption; … … 44 55 get { return caption; } 45 56 set { 46 57 if (InvokeRequired) { 47 Action<string> action = delegate (string s) { this.Caption = s; };58 Action<string> action = delegate (string s) { this.Caption = s; }; 48 59 Invoke(action, value); 49 60 } else { 50 61 if (value != caption) { … … 60 71 get { return this.readOnly; } 61 72 set { 62 73 if (InvokeRequired) { 63 Action<bool> action = delegate (bool b) { this.ReadOnly = b; };74 Action<bool> action = delegate (bool b) { this.ReadOnly = b; }; 64 75 Invoke(action, value); 65 76 } else { 66 77 if (value != readOnly) { 78 counters[4]++; 67 79 this.readOnly = value; 68 80 OnReadOnlyChanged(); 69 81 PropertyInfo prop = typeof(IView).GetProperty("ReadOnly"); … … 79 91 get { return base.Enabled; } 80 92 set { 81 93 if (base.Enabled != value) { 94 counters[5]++; 82 95 this.SuspendRepaint(); 83 96 base.Enabled = value; 84 97 this.ResumeRepaint(true); … … 162 175 if (InvokeRequired) 163 176 Invoke((MethodInvoker)OnReadOnlyChanged); 164 177 else { 178 counters[3]++; 165 179 EventHandler handler = ReadOnlyChanged; 166 180 if (handler != null) 167 181 handler(this, EventArgs.Empty); … … 184 198 } else PropagateStateChanges(c, type, propertyInfo); 185 199 } 186 200 } 201 202 protected override void OnPaint(PaintEventArgs e) { 203 base.OnPaint(e); 204 counters[0]++; 205 } 206 207 protected override void OnPaintBackground(PaintEventArgs e) { 208 base.OnPaintBackground(e); 209 counters[6]++; 210 } 211 212 protected override void OnLayout(LayoutEventArgs e) { 213 base.OnLayout(e); 214 counters[7]++; 215 } 216 217 protected override void OnResize(EventArgs e) { 218 if (IsHandleCreated) { 219 //this.SuspendRepaint(); 220 base.OnResize(e); 221 //this.ResumeRepaint(true); 222 } else { 223 base.OnResize(e); 224 } 225 counters[8]++; 226 } 227 228 private void Label_Paint(object sender, PaintEventArgs e) { 229 e.Graphics.FillRectangle(Brushes.LightGreen, new Rectangle(0, 0, 300, 15)); 230 var text = Name + " " + string.Join(" ", counters); 231 e.Graphics.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.ActiveCaptionText, new PointF(0, 0)); 232 } 233 187 234 public event EventHandler Changed; 188 235 protected virtual void OnChanged() { 189 236 if (InvokeRequired) 190 237 Invoke((MethodInvoker)OnChanged); 191 238 else { 239 counters[1]++; 192 240 EventHandler handler = Changed; 193 241 if (handler != null) 194 242 handler(this, EventArgs.Empty); … … 251 299 public void SuspendRepaint() { 252 300 if (InvokeRequired) 253 301 Invoke((MethodInvoker)SuspendRepaint); 254 else 302 else { 303 counters[2]++; 255 304 ((Control)this).SuspendRepaint(); 305 } 256 306 } 257 307 public void ResumeRepaint(bool refresh) { 258 308 if (InvokeRequired) -
View.Designer.cs
44 44 /// the contents of this method with the code editor. 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.label = new System.Windows.Forms.Label(); 47 48 this.SuspendLayout(); 48 49 // 49 // ViewBase50 // label 50 51 // 51 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 52 this.label.Location = new System.Drawing.Point(0, 0); 53 this.label.Name = "label"; 54 this.label.Size = new System.Drawing.Size(300, 15); 55 this.label.TabIndex = 0; 56 this.label.Text = "."; 57 // 58 // View 59 // 52 60 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 53 this.Name = "ViewBase"; 61 this.Controls.Add(this.label); 62 this.Name = "View"; 54 63 this.Load += new System.EventHandler(this.View_Load); 55 64 this.ResumeLayout(false); 56 65 … … 57 66 } 58 67 59 68 #endregion 69 70 private System.Windows.Forms.Label label; 60 71 } 61 72 }