Click or drag to resize

Referencing Controls

You can get a reference to a control using only the control's name if the control has not been added using script. When the script is being compiled, a property for each control is added to the ScreenScript class in a partial class that is not editable. This code looks something like the following:

public partial class ScreenScript : IDisposable
{
    // references to all controls on the current screen at compile time
    ControlPanel Panel1 { get { return Screen.ScreenControls["Panel1"] as ControlPanel; } }
    ControlButton Button1 { { return Screen.ScreenControls["Button1"] as ControlButton; } }
    ControlButton Button2 { { return Screen.ScreenControls["Button2"] as ControlButton; } }
    ControlValueBox ValueBox1 { { return Screen.ScreenControls["ValueBox1"] as ControlValueBox; } }
    ControlCircularGauge1 CircularGauge1 { { return Screen.ScreenControls["CircularGauge1"] as ControlCircularGauge; } }
}

Because these control references are created at compile time, you cannot access any controls that are created dynamically by script. Instead you will need to get the control from the ScreenControls collection.

// some arbitrary code
// NOTE: since these controls were already present when the screen was compiled we
// can access them using their names instead of having to get a reference to them
// using the Screen.ScreenControls collection.
object valueBox1Value = ValueBox1.Value?.Value;
if (valueBox1Value == 1)
    Button1.Text = "Hello";
else if (valueBox1Value == 0)
    Button2.Text = "Goodbye";

// controls that were added by script (methods that added controls not included here)
// NOTE: we need to get a reference to these controls using the Screen.ScreenControls
// collection because these controls were not defined as properties of the ScreenScript
// class when it was compiled.
ControlValueBox valueBox2 = Screen.ScreenControls["ValueBox2"] as ControlValueBox;
ControlButton button3 = Screen.ScreenControls["Button3"] as ControlButton;
ControlButton button4 = Screen.ScreenControls["Button4"] as ControlButton;

// some arbitrary code
object valueBox2Value = valueBox2.Value?.Value;
if (valueBox2Value == 1)
    button3.Text = "Hello";
else if (valueBox2Value == 0)
    button4.Text = "Goodbye";