搜档网
当前位置:搜档网 › [VCMFC]滑动动条控件Slider的用法

[VCMFC]滑动动条控件Slider的用法

[VCMFC]滑动动条控件Slider的用法
[VCMFC]滑动动条控件Slider的用法

[VC/MFC]滑动动条控件Slider的用法

在MFC中滑动条(CSliderCtrl)是个常用的控件,用法如下:

主要要方法有:

1、设置、取得滑动范围:

void SetRange( int nMin, int nMax, BOOL bRedraw = FALSE );

void GetRange( int& nMin, int& nMax ) const;

2、设置、取得按下左右箭头滑动间隔:

int SetLineSize( int nSize );

int GetLineSize( ) const;

3、设置、取得按下PgUp、PgDown时滑动间隔:

int SetPageSize( int nSize );

int GetPageSize( ) const;

4、设置、取得滑块位置:

void SetPos( int nPos );

int GetPos( ) const;

5、设置滑动条刻度的频度:

void SetTicFreq( int nFreq );

实例:

在对话框中放一个Slider控件,添加相应的Ctrl型变量为m_slider。在对话框初始化函数OnInitDialog()中添加:博彩评级https://www.sodocs.net/doc/962418136.html,

BOOL CDlgSetup::OnInitDialog()

{

CDialog::OnInitDialog();

// TODO: Add extra initialization here

m_slider.SetRang(0,100);//设置滑动范围

m_slider.SetTicFreq(10);//每10个单位画一刻度

return TRUE; // return TRUE unless you set the focus to a control

// EXCEPTION: OCX Property Pages should return FALSE

}

Slider控件本身并没有响应滑动的消息函数,但可以通过主窗体的OnHScroll()响应。在类向导中为对话框添加WM_HSCROLL消息,在响应函数中添加:

void CDlgSetup::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)

{

// TODO: Add your message handler code here and/or call default

CSliderCtrl *pSlidCtrl=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);

m_int=pSlidCtrlHue->GetPos();//取得当前位置值

CDialog::OnHScroll(nSBCode, nPos, pScrollBar);

}

//m_int 即为当前滑块的值。澳门新濠天地官网https://www.sodocs.net/doc/962418136.html,

wpf自定义slider控件

自定义Slider控件 最终效果: 界面: