13,767,570 members
See more:
Hi,

I've a vertical slider control in my program.
When I set the position of my slider to be in the zero position. it should be in the middle.

```m_slidervertical.SetBuddy(&m_ChartCtrl, FALSE);
m_slidervertical.SetRange(-10, 10);

m_slidervertical.SetPos(0);```

The range from -10 to 10, the middle should be 0. So when i set the position to 0, the slider should be in the middle. However, it does not appear in the middle. It appears on the top of the slider.

Can anyone please explain to me why?
Posted 17-Apr-12 20:04pm

Solution 1

That is because you have not set a Tic frequency value for your slider control. Means you must set a value to the slider control saying that your one Tic may move the control to just one position. For that write the code as below

```m_slidervertical.SetBuddy(&m_ChartCtrl, FALSE);
m_slidervertical.SetRange(-10, 10);
slidervertical.SetTicFreq( 1 );
m_slidervertical.SetPos(0);```
skfoo1 18-Apr-12 1:49am

I see. Thanks for your help.

I've got another question related to the slider control.

int nMinY = floor(m_dMinY);
int nMaxY = ceil(m_dMaxY);
m_nSliderVert = ((nMaxY + nMinY) / 2); // Get the middle of the range
m_slidervertical.SetBuddy(&m_ChartCtrl, FALSE);
m_slidervertical.SetRange(nMinY, nMaxY);
m_slidervertical.SetTicFreq(1);
m_slidervertical.SetPos(m_nSliderVert);

void CDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{

int nEndVal = m_slidervertical.GetPos();
double Shift = (double)(m_nSliderVert + nEndVal);

m_dSliderMinYShift = m_dMinY - Shift; // m_dMinY = Current Min value of the Y-axis
m_dSliderMaxYShift = m_dMaxY - Shift; // m_dMaxY = Current Max value of the Y-axis

// Do Panning.
// Get Current Min & Max values of the Y-axes.
}

When ever i scroll up or down, the graphs will move. But after a while, the values of the Y-axis will be very large, and the graphs will be moved out of range. I've tried to use the original values of the Y-axis to calculate the shifting. But it can only works when the graphs are in the original state. If the graphs are zoomed-in, and the slider is dragged, the shifting is still using the original values which is wrong. It should be using the current Max & Min values of the Y-axis. How can i solve this problem? Hope I make the question clear. Pardon my bad English.
Resmi Anna 18-Apr-12 2:25am

Unfortunately i didnt get your question:(...Please mark the above question as solved and post the current question as a new one. So that everyone can view this and someone can help you.

Top Experts
Last 24hrsThis month
 OriginalGriff 501 CPallini 200 CHill60 195 Bryian Tan 105 Richard Deeming 90
 OriginalGriff 2,842 Richard MacCutchan 1,715 CPallini 904 MadMyche 785 CHill60 495