C++/MFC-Spin

来源:互联网 发布:中国房地产未来知乎 编辑:程序博客网 时间:2024/04/28 07:14

一般次控件与Edit联合使用。


一、CSpinButtonCtrl控件属性

1.添加EDIT控件

2.添加Spin控件

   如果不是这样的顺序的话,使用ctrl+D改变Tab顺序,使spin紧靠edit后面

3.在EDIT控件上面设置group属性true(特别注意)

4.设置Spin属性

Auto Buddy              //为 true 表示按Z序自动关联一个伙伴窗口

Set Buddy Integer    //为 true 表示在伙伴窗口上显示数值
Alignment                //为 Right Align表示spin控件在伙伴窗口中右对齐

Orientation              // 水平,还是垂直

Wrap                       //为 true 表示数值超过范围时循环

Arrow keys              //为True(当按下向上和向下方向键时,控件可以增加或减小)

二、CSpinButtonCtrl类常用成员函数

SetAccel

为spin按钮设置一个加速值。

GetAccel

Retrieves acceleration information for a spin button control.

SetBase

此成员函数用来设置一个旋转按钮控件的基数。这个基数值决定了伙伴窗口显示的数字是十进制的还是十六进制的。

十六进制的数总是无符号的;十进制的数是有符号的。

GetBase

Retrieves the current base for a spin button control.

SetBuddy

为spin按钮设置一个伙伴窗口,点击spin按钮时焦点会落在这个伙伴窗口上

GetBuddy

Retrieves a pointer to the current buddy window.

SetPos

为spin控件设置一个当前位置。

GetPos

Retrieves the current position of a spin button control.

SetRange

设置范围值。

GetRange

Retrieves the upper and lower limits (range) for a spin button control.

SetRange32

设置32位的范围值

GetRange32

Retrieves the 32-bit range for a spin button control.

 三、应用示例

方法一:使用GetDlgItem指针

CSpinButtonCtrl* pSpin=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN1);CEdit* pedt=(CEdit*)GetDlgItem(IDC_EDIT2);pSpin->SetBuddy(pedt);//设置合作者窗口,即手动绑定pSpin->SetRange32(0,1000);//设置范围pSpin->SetBase(10);//设置基数,进制或者进制显示UDACCEL a[2];//for 赋值a[0].nSec=1;//过1秒a[0].nInc=1;//增加1a[1].nSec=3;//过3秒a[1].nInc=20;//增加20pSpin->SetAccel(2,a);//设置加速度,2指a[2]

方法二:控件变量

CSpinButtonCtrl m_Spin






原创粉丝点击