Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to write code to limit the range of digital input in MFC edit box, such as 1- 100, and automatically return to the initial input state when the input exceeds the range.
How to write code to limit the range of digital input in MFC edit box, such as 1- 100, and automatically return to the initial input state when the input exceeds the range.
1. directly define the edit box as an int variable, assuming the name is m _ nedit.

2. add testlistboxdlg:: dodataexchange (CDATA exchange * pdx) function in Void.

DDX_Text(pDX,IDC_EDIT 1,m _ nEdit); The second parameter is the ID of the edit box.

3. Right-click the edit box and add the EN_CHANGE message response method.

4. Add the following code to this method:

void CTESTLISTBOXDlg::onenchangeedit 1()

{

update data(TRUE);

if(m _ nEdit & gt; 100)

{

m _ nEdit = 0;

update data(FALSE);

}

}