Click or drag to resize

Changing Control Properties

The following code snippets show how control properties can be changed. Each control has a different set of properties available to it. See documentation on specific controls to determine what properties a control has, or use the static ControlBase methods to get/set properties of a ControlBase without casting to a specific control type.

ControlBase

// control object that was passed into an event delegate
object sender;

if (ControlBase.HasProperty(sender, "Text"))
{
    // check if control base has property before setting because
    // an exception will be thrown if the control base does not
    // have the specified property.
    ControlBase.SetProperty(sender, "Text", "Hello World");
}

// using the try methods will catch any errors so we do not need to check
// if the control has the property. This will not do anything if the control
// does not have the specified property.
ControlBase.TrySetProperty(sender, "FontSize", PropertyFontSize.Large);

ControlValueBox

C#
// get reference to a control in the current screen assuming there is
// a ValueBox control named "ValueBox1"
string valueBoxName = "ValueBox1";
ControlValueBox valueBox = Screen.ScreenControls[valueBoxName] as ControlValueBox;

// change color of ValueBox based on its value
double number;
TVQ tvq = valueBox.Value; // GET ControlValueBox.Value properties
object value = tvq?.Value;
if (double.TryParse(value?.ToString() ?? "NaN", out number)
{
    Color color = number > 10
        ? Color.Red
        : Color.Empty;
    valueBox.Color = color; // SET ControlValueBox.Color property
}

ControlCircularGauge

C#
// get reference to a control in the current screen assuming there is
// a CircularGauge control named "CircularGauge1"
string circularGaugeName = "CircularGauge1";
ControlCircularGauge circularGauge = Screen.ScreenControls[circularGaugeName] as ControlCircularGauge;

// change scale of CircularGauge based on its value
double number;
TVQ tvq = circularGauge.Value; // GET ControlCircularGauge.Value property
object value = tvq?.Value;
if (double.TryParse(value?.ToString() ?? "NaN", out number)
{
    double scaleMax = number > 10
        ? scaleMax = 100
        : scaleMax = 10;
    circularGauge.ScaleMax = scaleMax; // SET ControlCircularGauge.ScaleMax property
}