Change textbox text dynamically

Created at 27 Apr 2022, 16:49
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid1980098

Joined 03.02.2022

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.


@ctid1980098
Replies

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