Change textbox text dynamically
Created at 27 Apr 2022, 16:49
CT
Change textbox text dynamically
27 Apr 2022, 16:49
Hi,
I would like to change the text of a textbox in OnStart() from Ontick(). Is this possible?
protected override void OnStart() {
var rate = new TextBlock {
Text = ""
};
}
protected override void OnTick() {
//I would like to do something like...
rate.Text = "xyz"; //value changes with every tick
}
Any guidance will be appreciated.
amusleh
28 Apr 2022, 09:21
Hi,
You should declare text box as a field of your cBot/Indicator class, then you will be able to access it from anywhere and change its properties, example:
using cAlgo.API; namespace NewcBot { [Robot(AccessRights = AccessRights.None)] public class NewcBot : Robot { private TextBlock _textBlock; protected override void OnStart() { _textBlock = new TextBlock { Text = "Initial text", ForegroundColor = Color.Red, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; Chart.AddControl(_textBlock); } protected override void OnTick() { _textBlock.Text = "New text"; _textBlock.ForegroundColor = Color.Green; } } }
@amusleh