Free cookie consent management tool by TermsFeed Policy Generator

Ticket #2978: CountViewEvents.patch

File CountViewEvents.patch, 5.3 KB (added by gkronber, 6 years ago)
  • View.cs

     
    2020#endregion
    2121
    2222using System;
     23using System.Diagnostics;
     24using System.Drawing;
    2325using System.Linq;
    2426using System.Reflection;
    2527using System.Windows.Forms;
     
    2729namespace HeuristicLab.MainForm.WindowsForms {
    2830  public partial class View : UserControl, IView {
    2931    private bool initialized;
     32    public int[] counters = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    3033    public View() {
    3134      InitializeComponent();
     35      label.Paint += Label_Paint;
     36
    3237      this.initialized = false;
    3338      this.isShown = false;
    3439      this.closeReason = CloseReason.None;
     
    3742        this.Caption = ViewAttribute.GetViewName(this.GetType());
    3843      else
    3944        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();
    4051    }
    4152
    4253    private string caption;
     
    4455      get { return caption; }
    4556      set {
    4657        if (InvokeRequired) {
    47           Action<string> action = delegate(string s) { this.Caption = s; };
     58          Action<string> action = delegate (string s) { this.Caption = s; };
    4859          Invoke(action, value);
    4960        } else {
    5061          if (value != caption) {
     
    6071      get { return this.readOnly; }
    6172      set {
    6273        if (InvokeRequired) {
    63           Action<bool> action = delegate(bool b) { this.ReadOnly = b; };
     74          Action<bool> action = delegate (bool b) { this.ReadOnly = b; };
    6475          Invoke(action, value);
    6576        } else {
    6677          if (value != readOnly) {
     78            counters[4]++;
    6779            this.readOnly = value;
    6880            OnReadOnlyChanged();
    6981            PropertyInfo prop = typeof(IView).GetProperty("ReadOnly");
     
    7991      get { return base.Enabled; }
    8092      set {
    8193        if (base.Enabled != value) {
     94          counters[5]++;
    8295          this.SuspendRepaint();
    8396          base.Enabled = value;
    8497          this.ResumeRepaint(true);
     
    162175      if (InvokeRequired)
    163176        Invoke((MethodInvoker)OnReadOnlyChanged);
    164177      else {
     178        counters[3]++;
    165179        EventHandler handler = ReadOnlyChanged;
    166180        if (handler != null)
    167181          handler(this, EventArgs.Empty);
     
    184198        } else PropagateStateChanges(c, type, propertyInfo);
    185199      }
    186200    }
     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
    187234    public event EventHandler Changed;
    188235    protected virtual void OnChanged() {
    189236      if (InvokeRequired)
    190237        Invoke((MethodInvoker)OnChanged);
    191238      else {
     239        counters[1]++;
    192240        EventHandler handler = Changed;
    193241        if (handler != null)
    194242          handler(this, EventArgs.Empty);
     
    251299    public void SuspendRepaint() {
    252300      if (InvokeRequired)
    253301        Invoke((MethodInvoker)SuspendRepaint);
    254       else
     302      else {
     303        counters[2]++;
    255304        ((Control)this).SuspendRepaint();
     305      }
    256306    }
    257307    public void ResumeRepaint(bool refresh) {
    258308      if (InvokeRequired)
  • View.Designer.cs

     
    4444    /// the contents of this method with the code editor.
    4545    /// </summary>
    4646    private void InitializeComponent() {
     47      this.label = new System.Windows.Forms.Label();
    4748      this.SuspendLayout();
    4849      //
    49       // ViewBase
     50      // label
    5051      //
    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      //
    5260      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    53       this.Name = "ViewBase";
     61      this.Controls.Add(this.label);
     62      this.Name = "View";
    5463      this.Load += new System.EventHandler(this.View_Load);
    5564      this.ResumeLayout(false);
    5665
     
    5766    }
    5867
    5968    #endregion
     69
     70    private System.Windows.Forms.Label label;
    6071  }
    6172}