CheckBox alwyas clicked

Created at 09 Nov 2023, 12:10
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!
EY

eynt

Joined 08.05.2020

CheckBox alwyas clicked
09 Nov 2023, 12:10


I've added a static loaction CheckBox using the code below. The problem is that the checkbox is checked/unchecked every time the CHART is clicked instead of changing only when the CHECKBOX itself is clicked.

Thanks

 

CheckBox checkBox = new();
checkBox.IsVisible = true;
checkBox.Text = "MyCheckBox";
Chart.AddControl(checkBox);

@eynt
Replies

firemyst
10 Nov 2023, 01:15

You haven't added any event handlers to your checkbox.

 

You also need to add the checkbox to a canvas, and then add the canvas to the chart.


checkBox.Checked += CheckBox_Checked;
checkBox.Unchecked += CheckBox_Unchecked;
Canvas checkboxCanvas = new Canvas();
checkboxCanvas.AddChild(checkBox);
Chart.AddControl(checkboxCanvas);


@firemyst

eynt
10 Nov 2023, 04:10

RE: CheckBox alwyas clicked

Thank you.

It does work, however, I have another problem. I changed the code so it would change the indicator's parameter which is called LOAD_INDICATOR. However, although the print says its value is changed, when I go to the object manager to see the indicator's parameter value, over there it's not changed.

 

 

[Parameter(DefaultValue = false)]
        public bool LOAD_INDICATOR { get; set; }

private void CheckBox_Changed(CheckBoxEventArgs e)
        {
            Print("CheckBox_Changed 1");
            LOAD_INDICATOR = (bool)e.CheckBox.IsChecked;
            Print("LOAD_INDICATOR= " + LOAD_INDICATOR);
        }

@eynt

firemyst
10 Nov 2023, 05:40 ( Updated at: 10 Nov 2023, 06:26 )

RE: RE: CheckBox alwyas clicked

eynt said: 

Thank you.

It does work, however, I have another problem. I changed the code so it would change the indicator's parameter which is called LOAD_INDICATOR. However, although the print says its value is changed, when I go to the object manager to see the indicator's parameter value, over there it's not changed.

 

 

[Parameter(DefaultValue = false)]        public bool LOAD_INDICATOR { get; set; }private void CheckBox_Changed(CheckBoxEventArgs e)        {            Print("CheckBox_Changed 1");            LOAD_INDICATOR = (bool)e.CheckBox.IsChecked;            Print("LOAD_INDICATOR= " + LOAD_INDICATOR);        }

Looks to me like your cast is wrong.

You appear to be converting “e” to a bool, which I'm sure isn't what you want to do. :-)


@firemyst

eynt
10 Nov 2023, 08:04

I've changed the code to the following, it still acts the same

Thank you

 

 

private void CheckBox_Checked(CheckBoxEventArgs e)
        {
            Print("CheckBox_Checked");
            LOAD_INDICATOR = true;// (bool)e.CheckBox.IsChecked;
            Print("LOAD_INDICATOR= " + LOAD_INDICATOR);
        }

        private void CheckBox_Unchecked(CheckBoxEventArgs e)
        {
            Print("CheckBox_Unchecked 1");
            LOAD_INDICATOR = false;
            Print("LOAD_INDICATOR= " + LOAD_INDICATOR);
        }

@eynt