First thing you need to do is open up the screen's cs file that you want to loop through the controls on. Screen cs files are only created after you build your project. They are located in "TextControlLoop\BuildFiles", where "TextControlLoop" is the name of the project you are working on.
The iX Text control is stored as a Neo.ApplicationFramework.Controls.Controls.Label in "FSystemInfo.cs". Normally I would use the control like, "this.TQTERM_A7.Text = "New Text";". As we can see in the cs file, TQTERM_A7 is function that simply castes "m_TQTERM_A7" into a TextControlCFAdapter.
Here is the code:
Code: Select all
//--------------------------------------------------------------
// Press F1 to get help about using script.
// To access an object that is not located in the current class, start the call with Globals.
// When using events and timers be cautious not to generate memoryleaks,
// please see the help for more information.
//---------------------------------------------------------------
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using System.Reflection;
using Neo.ApplicationFramework.Controls.Script;
public partial class FSystemInfo
{
void Button1_Click(System.Object sender, System.EventArgs e)
{
//If you look at the FSystemInfo.cs file that is generated, you will see a field called m_TQTERM_A7.
//That field is used to hold the Text control on our screen. It is of type Label in the case of
//a Text control.
TextControlCFAdapter myTxt = GetTextBox("m_TQTERM_A7");
//Now we can use the text control just like we can if we do 'this.TQTERM_A7.Text = "New Text"'
myTxt.Text = "New Text";
}
//This function takes a string that repersents the name of an iX Text control that is part of this screen.
//The field names can be found by looking at this screen's cs file found in the project folder.
public TextControlCFAdapter GetTextBox(string txtName){
//Get the type of this screen
Type FormType = this.GetType();
//Get the field from the type
FieldInfo field = FormType.GetField(txtName,BindingFlags.NonPublic | BindingFlags.Instance);
if( field != null ){
//Use the instance of this screen to get the instance of the field
Neo.ApplicationFramework.Controls.Controls.Label lb;
lb = (Neo.ApplicationFramework.Controls.Controls.Label) field.GetValue(this);
//Cast the Label into a Text control. This code was pulled from the TQTERM_A7 function and can be
//found in the cs file associated with this screen.
TextControlCFAdapter myTxt;
myTxt = this.AdapterService.CreateAdapter<Neo.ApplicationFramework.Controls.Script.TextControlCFAdapter>(lb);
return myTxt;
}
return null;
}
}
}