Click or drag to resize

Adding/Removing Controls

The following code snippets can be used to add/remove controls from a parent control.

Add Controls

C#
// get reference to a parent control in the current screen assuming there is
// a panel control named "Panel1"
string panelName = "Panel1";
ControlPanel panel = Screen.ScreenControls[panelName] as ControlPanel;

// create value box control that we will add to the panel control
string controlName = null; // null will auto assign control name that is unique within the current screen
string sourceTag = "<server>view.tag";
ControlValueBox valueBox = ControlFactory.CreateControl(ControlKind.ValueBox, controlName) as ControlValueBox;
valueBox.SourceTag = sourceTag; // assign source tag used to determine what data to fetch when drawing trend
valueBox.X = 100; // relative x-position
valueBox.Y = 100; // relative y-position

// add newly created value box to the panel control children collection
panel.Children.Add(valueBox);

Remove Controls

C#
// get reference to a parent control in the current screen assuming there is
// a panel control named "Panel1"
string panelName = "Panel1";
ControlPanel panel = Screen.ScreenControls[panelName] as ControlPanel;

// get child control by control name assuming a panel has a child control
// named "ValueBox1"
string childControlName = "ValueBox1";
ControlValueBox valueBox1 = panel.Children[childControlName] as ControlValueBox;

// get child control control by index assuming there are at least 3 child
// controls in the panel
int childControlIndex = 2;
ControlBase childAtIndex2 = panel.Children[childControlIndex] as ControlBase;

// remove selected child trends from trend graph control
panel.Children.Remove(valueBox1);
panel.Children.Remove(childControlAtIndex2);

// remove all controls from panel control
panel.Children.Clear();