たとえば、2つのラベルがあります。最初のラベルは次のとおりです。
気温は今-
そして2番目のラベル:
46c
しかし、時々、温度が100に達するかどうかという質問のためだけに、次のようにする必要があります。
温度は今-100cです
しかし、100のcは、他のラベルの「-」を超えます。したがって、2桁の場合は問題ありませんが、3桁の場合は他のラベルを超えます。
ラベルを計算したり、数字で自動的に更新したりして、現在の桁数と他のラベルの場所に応じて場所を変更し、他のラベルの場所に重ならないようにする方法はありますか?
コンストラクター内の私のコード。
temperature_label = new Label();
textMode_label = new Label();
this.Controls.Add(textMode_label);
this.Controls.Add(temperature_label);
temperature_label.Location = new Point(260, 200);
temperature_label.Height = 250;
temperature_label.Width = 500;
temperature_label.ForeColor = Color.Red;
temperature_label.Font = new Font("Arial", 35, FontStyle.Bold);
temperature_label.Text = "200c";
textMode_label.Location = new Point(350, 200);
textMode_label.Height = 250;
textMode_label.Width = 500;
textMode_label.ForeColor = Color.Blue;
textMode_label.Font = new Font("Arial", 35, FontStyle.Bold);
textMode_label.Text = "The Temperature Now Is - ";
次に、タイマーティックイベントで、温度ラベルを次の値で更新します。
private void timer_Tick(object sender, EventArgs e)
{
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();
temperature_label.Text = sensor.Value.ToString()+ "c";
timer.Interval = 1000;
if (sensor.Value > 90)
{
Logger.Write("The current temperature is ===> " + sensor.Value);
button1.Enabled = true;
}
this.Select();
}
}
}
}
}