I have two labels for example the first one is:
The temperature is now –
And the second label:
46c
But if sometimes only for the question if the temperature will get hight to 100 so it should be:
The temperature is now – 100c
But then the c of the 100 will get over the “-” of the other label. So if its two digits its ok but if its three digits its getting over the other label.
Is there any way to calculate or to update automatic the label with the numbers so it will change its location according to the number of digits currently it has and according to the other label location so they wont get one over the other one ?
My code in the constructor.
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 - ";
Then in the timer tick event im updating the temperature_label with the values:
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();
}
}
}
}
}
You could use a single lable instead of two and do a string.Format on the text.
Use the Tag-property of the label to hold the text you want to format and, after formatting, assign it as the labels text.
So something along the line of:
and then in the inner-loop of your tick-handler:
This only works if there is no need to right align the temperature value, though.