Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

C++
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

1 solution

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

C#
m_slidervertical.SetBuddy(&m_ChartCtrl, FALSE);
m_slidervertical.SetRange(-10, 10);
slidervertical.SetTicFreq( 1 );
m_slidervertical.SetPos(0);
 
Share this answer
 
Comments
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900