How can i reduce this ugly block of text? I wanted to use a for loop, but i need to refer to different objects for each iteration of ids .... temperature (i). Also, if i were to rename my objects to LB_Something0, LB_Something1, how could i incorporate that into the for loop?
LB_NeedleHeater.Text = IDS.Devices.Thermal.FrmThermal.Temperature(0)
FrmProduction.Needle.Text = IDS.Devices.Thermal.FrmThermal.Temperature(0)
LB_SyrHeater.Text = IDS.Devices.Thermal.FrmThermal.Temperature(1)
FrmProduction.Syringe.Text = IDS.Devices.Thermal.FrmThermal.Temperature(1)
LB_PreHeater.Text = IDS.Devices.Thermal.FrmThermal.Temperature(2)
FrmProduction.Station1.Text = IDS.Devices.Thermal.FrmThermal.Temperature(2)
LB_DispHeater.Text = IDS.Devices.Thermal.FrmThermal.Temperature(3)
FrmProduction.Station2.Text = IDS.Devices.Thermal.FrmThermal.Temperature(3)
LB_PostHeater.Text = IDS.Devices.Thermal.FrmThermal.Temperature(4)
FrmProduction.Station3.Text = IDS.Devices.Thermal.FrmThermal.Temperature(4)
You could do it by naming your controls suffixed with a counter, like:
Then use that counter to find the control. Something like this:
Note: Mark the second parameter to
Find
asTrue
if you want to search all child controls as well.Find
returns an array so pick the first one.Ref: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.find(v=vs.100).aspx