Discussion of article "Graphical Interfaces VI: the Checkbox Control, the Edit Control and their Mixed Types (Chapter 1)" - page 2
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
...
Thanks for the tip!
I will add this capability. Watch for updates future articles in this series.
in your examples there is always output id, lparam, dparam, sparam.
if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
{
::Print(__FUNCTION__," > id: ",id,"; lparam: ",lparam,"; dparam: ",dparam,"; sparam: ",sparam);
//Print(m_spin_edit1.GetValue());
}
we get the following
TestLibrary (NZDUSD,H1) CProgram::OnEvent > id: 1020; lparam: 12; dparam: -1.0; sparam: Spin Edit 1:
id - element identifier
lparam - ?
dparam - ?
sparam - element name
we are considering an input field - of course it is interesting to get the entered value, how to do it as fast as possible?
in your examples there is always id, lparam, dparam, sparam output.
...
id - element identifier
lparam - ?
dparam - ?
sparam - element name
Controls generate messages and parameters in most cases mean the following:
I will prepare later a table showing the set of event parameters from each element.
...
we consider an input field - of course it is interesting to get the entered value, how to do it as fast as possible?
Just using the CSpinEdit::GetValue() method you can get the current value in the input field.
Example:
if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
{
//--- If the item ID is from the first input field
if(lparam==m_spin_edit1.Id())
{
//--- Output its value
Print("m_spin_edit1.GetValue(): ",m_spin_edit1.GetValue());
}
//---
return;
}
And if we don't know the name or we have a hundred fields, maybe there is a method by id to see what is there or something like this.GetValue().
So each element has its own unique element identifier.
if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
{
if(lparam==m_spin_edit1.Id()){Print(m_spin_edit1.GetValue());}
if(lparam==m_spin_edit2.Id()){Print(m_spin_edit2.GetValue());}
if(lparam==m_spin_edit3.Id()){Print(m_spin_edit3.GetValue());}
if(lparam==m_spin_edit4.Id()){Print(m_spin_edit4.GetValue());}
if(lparam==m_spin_edit5.Id()){Print(m_spin_edit5.GetValue());}
if(lparam==m_spin_edit6.Id()){Print(m_spin_edit6.GetValue());}
if(lparam==m_spin_edit7.Id()){Print(m_spin_edit7.GetValue());}
if(lparam==m_spin_edit8.Id()){Print(m_spin_edit8.GetValue());}
if(lparam==m_spin_edit9.Id()){Print(m_spin_edit9.GetValue());}
...
}
I meant not to write such code, maybe it makes sense to do it.
if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
{
Print(GetValue(lparam));
или
Print(this.GetValue());
}
but I don't have a lot of fields, the first option is fine for me.
Pavel Kolchin:
...
I meant not to write such code, maybe it makes sense to do it.
if(id==CHARTEVENT_CUSTOM+ON_END_EDIT)
{
Print(GetValue(lparam));
или
Print(this.GetValue());
}
//| ChartEvent function|
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
program.ChartEvent(id,lparam,dparam,sparam);
if(lparam==program.m_checkbox.Id())
if(program.m_checkbox.CheckButtonState())
{
program.m_checkbox.LabelColor(clrGreen);
}
else
{
program.m_checkbox.LabelColor(clrRed);
}
}
//+------------------------------------------------------------------+
Alexander Fedosov:
Simple task. Change the colour of the checkbox label when clicking on the checkbox. Ticked - green text, unchecked - red. It doesn't work. Unchecked it becomes blue, ticked it is still blue.Now you can set colours for different states only before the item is installed(example below):
//|| Creates checkbox 1|
//+------------------------------------------------------------------+
bool CProgram::CreateCheckBox1(const int x_gap,const int y_gap,string text)
{
//--- Save the window pointer
m_checkbox1.WindowPointer(m_window1);
//--- Set properties before creation
m_checkbox1.XSize(90);
m_checkbox1.YSize(18);
m_checkbox1.LabelColor(clrGreen);
m_checkbox1.LabelColorOff(clrRed);
m_checkbox1.LabelColorHover(clrCornflowerBlue);
m_checkbox1.LabelColorLocked(clrSilver);
//--- Create a control
if(!m_checkbox1.CreateCheckBox(m_chart_id,m_subwin,text,x_gap,y_gap))
return(false);
//--- Add the object to the common array of object groups
CWndContainer::AddToElementsArray(0,m_checkbox1);
return(true);
}
//| ChartEvent function|
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
program.ChartEvent(id,lparam,dparam,sparam);
if(lparam==program.m_checkbox.Id())
if(program.m_checkbox.CheckButtonState())
{
program.m_checkbox.LabelColor(clrGreen);
}
else
{
program.m_checkbox.LabelColor(clrRed);
}
}
//+------------------------------------------------------------------+
How about this?
{
if(program.m_checkbox.CheckButtonState()) program.m_checkbox.LabelColor(clrGreen);
else program.m_checkbox.LabelColor(clrRed);
}