简体   繁体   English

我可以使用编辑框中的值(数字)将其设置为滚动条上的位置吗? 如果是,那怎么办?

[英]Can I use the value(numeric) in the edit box to set it as the position on a scroll bar? If yes, then how?

Suppose in a dialog based application, I have a scroll bar and an edit box to display the position of the scroll bar. 假设在基于对话框的应用程序中,我有一个滚动条和一个编辑框来显示滚动条的位置。

Now, I want to improvise and put a value in the edit box myself and as soon as I type it, the scroll bar scrolls to that position. 现在,我想即兴创作并在编辑框中输入一个值,键入后,滚动条就会滚动到该位置。

  • you can select edit control and go to property window and make Number as TRUE. 您可以选择编辑控件并转到属性窗口,然后将Number设置为TRUE。
    By this user can only enter numeric value in editbox. 该用户只能在编辑框中输入数字值。
    在此处输入图片说明

  • Use SetLimitText(); 使用SetLimitText(); function to limit the length of character in edit control. 功能限制编辑控件中字符的长度。

     m_edit.SetLimitText(2); // this will accept value from 0 to 99 
  • Call ON_EN_UPDATE this function will call every time when edit Control value changes. 调用ON_EN_UPDATE此函数将在每次编辑控制值更改时调用。

在此处输入图片说明

Inside this function you can get the value of edit control. 在此函数内,您可以获得编辑控件的值。

CString strTxt;
m_edit.GetWindowText(strTxt);
int nIndex = _ttoi(strTxt);  // you will get integer value here.

Use this integer value to set the position of scroll bar. 使用此整数值设置滚动条的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM