如何显示最高温度和最低温度?

时间:2013-12-29 20:41:59

标签: c# winforms

我的程序每x秒显示一次GPU视频卡的温度。 我想每次都会显示最低温度和最高温度。

例如,温度为:49c 然后它变为51然后再变为45然后再变为49.

所以最大值是51最小值是45。 如果温度升高到51以上,那么最大值将会改变。 并且最低限度相同。

private void timer_Tick(object sender, EventArgs e)
        {
            if (textBox3.Text == "")
            {
                timer.Stop();
                MessageBox.Show("אנא הכנס נתונים בתיבות הטקסט מצד שמאל כדי להמשיך");
            }
            else
            {
                timer.Start();
                Computer computer = new Computer();
                computer.Open();
                computer.GPUEnabled = true;

                foreach (var hardwareItem in computer.Hardware)
                {

                    if (hardwareItem.HardwareType == HardwareType.GpuNvidia)
                    {
                        foreach (var sensor in hardwareItem.Sensors)
                        {
                            if (sensor.SensorType == SensorType.Temperature)
                            {
                                sensor.Hardware.Update();
                                //textBox1.Text = String.Format("The current temperature is {0}", sensor.Value);
                                temperature_label.Text = sensor.Value.ToString() + "c";
                                label8.Text = sensor.Value.ToString() + "c"; // to save the last maximum temperature to a external variable and then show it in label8 same for the minimum temperature \\
                                label8.Visible = true;
                                int t = temperature_label.Text.Length;
                                if (t > 3)
                                {
                                    temperature_label.Location = new Point(238, 200);
                                }
                                timer.Interval = 1000;
                                if (sensor.Value > float.Parse(textbox3_value))
                                {
                                    Logger.Write("The current temperature is ===> " + sensor.Value);
                                    button1.Enabled = true;
                                    //  temperature_label.ForeColor = Color. // to check wich colors to use blue and red regular state and in emergency when its over 90c ?! what colors for each label ?
                                }
                                this.Select();
                            }
                        }
                    }
                }
            }
        }

我有一个计时器刻度事件,我更新温度。 在label8中我想显示最大值。 现在就是它实时显示温度的方式。

2 个答案:

答案 0 :(得分:1)

只需添加两个变量即可存储最高和最低温度:

double minTemp = Double.MaxValue,maxTemp = Double.MinValue;

并且:

double value = Convert.ToDouble(sensor.Value);

if(value < minTemp) minTemp = value;
else if(value > maxTemp) maxTemp = value;

lblMin.Text =  minTemp.ToString() + "c";
lblMax.Text =  maxTemp.ToString() + "c";

答案 1 :(得分:0)

您可能需要三个标签和三个变量:

  // Example
  tempCurrent = sensor.Value;
  if (tempMax < tempCurrent)
    tempMax = tempCurrent;
  if (tempMin > tempCurrent)
    tempMin = tempCurrent;

  lblMax.Text = tempMax + "c";
  lblMin.Text = tempMin + "c";
  lblCurrent.Text = tempCurrent + "c";
相关问题