Add a numeric UI control
Add a numeric UI control
29 Aug 2022, 16:11
Currently, we only have text UI controls, i.e. TextBlock and TextBox. There should be ones for numbers only too, like the ones that are already in cTrader, where you can only input numbers, for cBot parameters, stop loss/tp and etc.
Functionality should be exactly the same: can only input numbers, and scrolling on it should increment/decrement it by step. Perhaps also could have min/max values too.
Replies
BigManDave
31 Aug 2022, 16:33
RE:
firemyst said:
They are already there.
Just declare the parameter to be a type of "int" or "double".
Then you can apply the min/max settings, "step" setting, etc.
As far as I am aware, they are not already there, because I asked Panagiotis and he said this functionality doesn't exist in the cAlgo API.
TextBlock and TextBox do not have any parameters as far as I know. Please can you give a code example of what you are talking about?
@BigManDave
firemyst
01 Sep 2022, 04:31
RE: RE:
BigManDave said:
firemyst said:
They are already there.
Just declare the parameter to be a type of "int" or "double".
Then you can apply the min/max settings, "step" setting, etc.
As far as I am aware, they are not already there, because I asked Panagiotis and he said this functionality doesn't exist in the cAlgo API.
TextBlock and TextBox do not have any parameters as far as I know. Please can you give a code example of what you are talking about?
Just because it's not in the cAlgoAPI doesn't mean it doesn't exist in the .net framework. You can build controls using Windows Forms.
In your case, you probably want a NumericUpDown control. You can also use a TextBox control, and on the KeyPress event, check to make sure it's numeric only.
Here's the details from Microsoft on the NumericUpDown control:
and here's a blog with examples of that AND how to code a textbox so it accepts numbers only:
Here's an example from the cTrader repository that adds controls into cTrader:
https://ctrader.com/algos/cbots/show/2155
You can always check StackOverflow as well:
Simple code I use to add a checkbox to a chart to allow me to toggle things:
private CheckBox _checkBox;
private Canvas _checkboxCanvas;
//
//... and here's how to implement
//
_checkBox = new CheckBox
{
Text = "This is an example",
Margin = 5,
IsChecked = true,
Left = 10,
Top = 20
};
_checkBox.Checked += CheckBox_Checked;
_checkBox.Unchecked += CheckBox_Unchecked;
_checkboxCanvas = new Canvas();
_checkboxCanvas.AddChild(_checkBox);
//Add to the cTrader chart so I can check/uncheck it and have it do what I want
Chart.AddControl(_checkboxCanvas);
Hope that helps?
@firemyst
firemyst
31 Aug 2022, 15:52
They are already there.
Just declare the parameter to be a type of "int" or "double".
Then you can apply the min/max settings, "step" setting, etc.
@firemyst