PanelClientData.cs 4.3 KB

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