PanelClientData.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 ErgometerApplication
  9. {
  10. public class PanelClientData : Panel
  11. {
  12. public Label labelMetingCurrentValue;
  13. public ProgressBar progressBarMeting;
  14. public PictureBox rpmpicturebox;
  15. public Label metingName;
  16. private int min { get; set; }
  17. public int max { get; set; }
  18. private string name;
  19. public PanelClientData(string name, int min, int max) : base()
  20. {
  21. this.min = min;
  22. this.max = max;
  23. this.name = name;
  24. this.metingName = new System.Windows.Forms.Label();
  25. this.progressBarMeting = new System.Windows.Forms.ProgressBar();
  26. this.labelMetingCurrentValue = new System.Windows.Forms.Label();
  27. //
  28. // initialize panel
  29. //
  30. this.BackColor = System.Drawing.SystemColors.ControlLightLight;
  31. this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  32. this.Controls.Add(this.metingName);
  33. this.Controls.Add(this.labelMetingCurrentValue);
  34. if(name != "Tijd")
  35. this.Controls.Add(this.progressBarMeting);
  36. if (name == "RPM")
  37. {
  38. this.rpmpicturebox = new PictureBox();
  39. this.Controls.Add(this.rpmpicturebox);
  40. }
  41. this.Dock = System.Windows.Forms.DockStyle.Top;
  42. this.Location = new System.Drawing.Point(0, 0);
  43. this.Name = "panel1";
  44. this.Size = new System.Drawing.Size(284, 80);
  45. //
  46. // metingName
  47. //
  48. this.metingName.AutoSize = true;
  49. this.metingName.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  50. this.metingName.Location = new System.Drawing.Point(12, 9);
  51. this.metingName.Name = "metingName";
  52. this.metingName.Size = new System.Drawing.Size(105, 21);
  53. this.metingName.TabIndex = 0;
  54. this.metingName.Text = name;
  55. this.metingName.BackColor = System.Drawing.Color.Transparent;
  56. //
  57. // progressBarMeting
  58. //
  59. this.progressBarMeting.Location = new System.Drawing.Point(16, 39);
  60. this.progressBarMeting.Name = "progressBarMeting";
  61. this.progressBarMeting.Size = new System.Drawing.Size(183, 23);
  62. this.progressBarMeting.TabIndex = 1;
  63. this.progressBarMeting.Value = 0;
  64. //
  65. // labelMetingCurrentValue
  66. //
  67. this.labelMetingCurrentValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  68. this.labelMetingCurrentValue.AutoSize = true;
  69. this.labelMetingCurrentValue.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  70. this.labelMetingCurrentValue.Location = new System.Drawing.Point(210, 32);
  71. this.labelMetingCurrentValue.Name = "labelMetingCurrentValue";
  72. this.labelMetingCurrentValue.Size = new System.Drawing.Size(57, 32);
  73. this.labelMetingCurrentValue.TabIndex = 2;
  74. this.labelMetingCurrentValue.Text = "0";
  75. this.labelMetingCurrentValue.BackColor = System.Drawing.Color.Transparent;
  76. //rpm check
  77. if (name == "RPM")
  78. {
  79. this.rpmpicturebox.Location = new System.Drawing.Point(153, 32);
  80. this.rpmpicturebox.Size = new System.Drawing.Size(57, 32);
  81. this.rpmpicturebox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  82. this.rpmpicturebox.AutoSize = true;
  83. this.rpmpicturebox.SizeMode = PictureBoxSizeMode.StretchImage;
  84. this.rpmpicturebox.Name = "rpmbox";
  85. }
  86. }
  87. public void setText(string text)
  88. {
  89. this.metingName.Text = text;
  90. }
  91. public void updateValue(int value)
  92. {
  93. if(name == "RPM")
  94. {
  95. if(value < 45)
  96. {
  97. this.rpmpicturebox.Image = Properties.Resources.up;
  98. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Red;
  99. }
  100. else if( value > 55)
  101. {
  102. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Red;
  103. this.rpmpicturebox.Image = Properties.Resources.down;
  104. }
  105. else
  106. {
  107. this.labelMetingCurrentValue.ForeColor = System.Drawing.Color.Green;
  108. this.rpmpicturebox.Image = Properties.Resources.stay;
  109. }
  110. }
  111. if (name == "Tijd")
  112. {
  113. this.labelMetingCurrentValue.Text = Helper.SecondsToTime(value);
  114. }
  115. else
  116. {
  117. this.labelMetingCurrentValue.Text = value.ToString();
  118. this.progressBarMeting.Value = ValueToPercentage(value);
  119. }
  120. }
  121. public void updateValue(double value)
  122. {
  123. this.labelMetingCurrentValue.Text = value.ToString();
  124. this.progressBarMeting.Value = ValueToPercentage((int)value);
  125. }
  126. public void updateValue(decimal value)
  127. {
  128. this.labelMetingCurrentValue.Text = value.ToString();
  129. this.progressBarMeting.Value = ValueToPercentage((int)value);
  130. }
  131. private int ValueToPercentage(int value)
  132. {
  133. if (value < min)
  134. return 0;
  135. if (value > max)
  136. return 100;
  137. return ((value - min) * 100) / (max - min);
  138. }
  139. }
  140. }