Discussion:
Incrementing slider control values in 0.01 step
(too old to reply)
Lucress Carol
2012-04-11 11:57:00 UTC
Permalink
Hi every one,
I can not figure out how i can increment the value of my slider
control in 0.01 step. What's happening is that the step seems to be
0.08 instead of 0.01

BOOL CTestDlg:: OnInitDialog()
{
...
m_Slider.SetRange(0,1000); // from 0 to 10
m_Slider.SetTicFreq(1);
SetDlgItemText(IDC_SLIDER_VALUE, _T("0"));
}

void CTestDlg:: OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollbar)
{
m_SliderValue.Format(_T("%.2f"),(m_Slider.GetPos())*0.01);
SetDlgItemText(IDC_SLIDER_VALUE, m_SliderValue);
}

Could someone tell me what i'm overlooking ?
Thank you
s***@mvps.org
2012-04-11 12:33:08 UTC
Permalink
Post by Lucress Carol
Hi every one,
I can not figure out how i can increment the value of my slider
control in 0.01 step. What's happening is that the step seems to be
0.08 instead of 0.01
BOOL CTestDlg:: OnInitDialog()
{
...
m_Slider.SetRange(0,1000); // from 0 to 10
m_Slider.SetTicFreq(1);
SetDlgItemText(IDC_SLIDER_VALUE, _T("0"));
}
void CTestDlg:: OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollbar)
{
m_SliderValue.Format(_T("%.2f"),(m_Slider.GetPos())*0.01);
SetDlgItemText(IDC_SLIDER_VALUE, m_SliderValue);
}
Could someone tell me what i'm overlooking ?
Thank you
The slider control moves in units of pixels. If the size in pixels is less than the range you want (1000) then moving by one pixel has to change the reported position by more than 1.

In your case it looks like the slider is only 125 pixels long. So moving it by 1 pixel changes the reported position by (1000/125).
Lucress Carol
2012-04-11 12:47:48 UTC
Permalink
Post by s***@mvps.org
Post by Lucress Carol
Hi every one,
I can not figure out how i can increment the value of my slider
control in 0.01 step. What's happening is that the step seems to be
0.08 instead of 0.01
BOOL CTestDlg:: OnInitDialog()
{
   ...
   m_Slider.SetRange(0,1000); // from 0 to 10
   m_Slider.SetTicFreq(1);
   SetDlgItemText(IDC_SLIDER_VALUE, _T("0"));
}
void CTestDlg:: OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollbar)
{
  m_SliderValue.Format(_T("%.2f"),(m_Slider.GetPos())*0.01);
  SetDlgItemText(IDC_SLIDER_VALUE,  m_SliderValue);
}
Could someone tell me what i'm overlooking ?
Thank you
The slider control moves in units of pixels. If the size in pixels is less than the range you want (1000) then moving by one pixel has to change the reported position by more than 1.
In your case it looks like the slider is only 125 pixels long. So moving it by 1 pixel changes the reported position by (1000/125).- Zitierten Text ausblenden -
- Zitierten Text anzeigen -
Thank you

Loading...