PanelClientData.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using ErgometerLibrary;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace ErgometerDoctorApplication
  9. {
  10. public class PanelClientData : Panel
  11. {
  12. public Label labelMetingCurrentValue;
  13. public ProgressBar progressBarMeting;
  14. public Label metingName;
  15. private int min { get; set; }
  16. public int max { get; set; }
  17. private string name;
  18. public PanelClientData(string name, int min, int max) : base()
  19. {
  20. this.min = min;
  21. this.max = max;
  22. this.name = name;
  23. this.metingName = new System.Windows.Forms.Label();
  24. this.progressBarMeting = new System.Windows.Forms.ProgressBar();
  25. this.labelMetingCurrentValue = new System.Windows.Forms.Label();
  26. //
  27. // initialize panel
  28. //
  29. this.BackColor = System.Drawing.SystemColors.ControlLightLight;
  30. this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  31. this.Controls.Add(this.labelMetingCurrentValue);
  32. if (name != "Tijd")
  33. this.Controls.Add(this.progressBarMeting);
  34. this.Controls.Add(this.metingName);
  35. this.Dock = System.Windows.Forms.DockStyle.Top;
  36. this.Location = new System.Drawing.Point(0, 0);
  37. this.Name = "panel1";
  38. this.Size = new System.Drawing.Size(284, 80);
  39. //
  40. // metingName
  41. //
  42. this.metingName.AutoSize = true;
  43. this.metingName.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  44. this.metingName.Location = new System.Drawing.Point(12, 9);
  45. this.metingName.Name = "metingName";
  46. this.metingName.Size = new System.Drawing.Size(105, 21);
  47. this.metingName.TabIndex = 0;
  48. this.metingName.Text = name;
  49. //
  50. // progressBarMeting
  51. //
  52. this.progressBarMeting.Location = new System.Drawing.Point(16, 39);
  53. this.progressBarMeting.Name = "progressBarMeting";
  54. this.progressBarMeting.Size = new System.Drawing.Size(183, 23);
  55. this.progressBarMeting.TabIndex = 1;
  56. this.progressBarMeting.Value = 0;
  57. //
  58. // labelMetingCurrentValue
  59. //
  60. this.labelMetingCurrentValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  61. this.labelMetingCurrentValue.AutoSize = true;
  62. this.labelMetingCurrentValue.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  63. this.labelMetingCurrentValue.Location = new System.Drawing.Point(210, 32);
  64. this.labelMetingCurrentValue.Name = "labelMetingCurrentValue";
  65. this.labelMetingCurrentValue.Size = new System.Drawing.Size(57, 32);
  66. this.labelMetingCurrentValue.TabIndex = 2;
  67. this.labelMetingCurrentValue.Text = "0";
  68. }
  69. public void setText(string text)
  70. {
  71. this.metingName.Text = text;
  72. }
  73. public void updateValue(int value)
  74. {
  75. if (name == "Tijd")
  76. {
  77. this.labelMetingCurrentValue.Text = Helper.SecondsToTime(value);
  78. }
  79. else
  80. {
  81. this.labelMetingCurrentValue.Text = value.ToString();
  82. this.progressBarMeting.Value = ValueToPercentage(value);
  83. }
  84. }
  85. public void updateValue(double value)
  86. {
  87. this.labelMetingCurrentValue.Text = value.ToString();
  88. this.progressBarMeting.Value = ValueToPercentage((int)value);
  89. }
  90. public void updateValue(decimal value)
  91. {
  92. this.labelMetingCurrentValue.Text = value.ToString();
  93. this.progressBarMeting.Value = ValueToPercentage((int)value);
  94. }
  95. private int ValueToPercentage(int value)
  96. {
  97. if (value < min)
  98. return 0;
  99. if (value > max)
  100. return 100;
  101. return ((value - min) * 100) / (max - min);
  102. }
  103. }
  104. }