Topics

Forum Topics not found

Replies

redtick123
07 Jan 2020, 17:01 ( Updated at: 21 Dec 2023, 09:21 )

It's hard to do it with static text. If you want to control alignment it's better to use custom UI controls. You can use Grid to make a table. But it is a bit complicated, for each cell you need to create a TextBlock.

I'm working on DataGrid control, that makes it easier.

1. Get class from here and paste it to your cBot or indicator:
https://raw.githubusercontent.com/redtick123/cTraderRedUI/master/DataGrid.cs

2.  cBot with your example will look like this:

private DataGrid DataGrid;

protected override void OnStart()
{
    DataGrid = new DataGrid 
    {
        VerticalAlignment = VerticalAlignment.Top,
        HorizontalAlignment = HorizontalAlignment.Center,
        Margin = new Thickness(0, 40, 0, 0),
        CellsPadding = "12 6",
        CellsMargin = 2,
        CellsForegroundColor = "#ffffff",
        FontSize = 12
    };

    DataGrid.SetText("Opening Price", 0, 0);
    DataGrid.SetText(Bid.ToString(), 0, 1);
    DataGrid.SetText(Bid.ToString(), 0, 2);
    DataGrid.SetText(Bid.ToString(), 0, 3);

    DataGrid.SetText("Target met", 1, 0);

    DataGrid.SetText("No", 1, 1);
    DataGrid.SetCellBackgroundColor(1, 1, Color.Green);

    DataGrid.SetText("No", 1, 2);
    DataGrid.SetCellBackgroundColor(1, 2, Color.Green);

    DataGrid.SetText("Yes", 1, 3);
    DataGrid.SetCellBackgroundColor(1, 3, Color.Red);

    Chart.AddControl(DataGrid);
}

You can change text for cells as well foreground and background colors:


 


@redtick123