如果编辑控制框中输入的数字是偶数,如何按下按钮 [英] How to press the button in case if the number entered in edit control box is even
问题描述
如果在编辑控制框中输入的数字是偶数,我想按下按钮。
我是基于MFC Dialog的应用程序visual studio 2015的新手。
需要帮助
我尝试过:
如果在编辑控制框中输入的数字是偶数,我想按下按钮。
我是基于MFC Dialog的应用程序visual studio 2015的新手。
需要帮助
- 从编辑框中获取整数,例如
n
。- 检查
n
是偶数,即:bool is_even =(n%2 == 0);
- 调用按钮代码(我会把它放在一个单独的方法中)说
DoMyWonderfulAction
然后从代码和按钮调用它。)
请注意,有几种方法可以实现点1
。如果编辑框已映射到整数变量(UpdateData
机制),则效果更好。否则你必须得到字符串(例如通过GetWindowText
方法),然后解析它(例如,通过 _ ttoi [ ^ ])以获取整数值。
引用:是的我想点击代码中的按钮。
如果在编辑控制框中输入的变量甚至是按钮被点击。
这是一个坏的想法!
想象一下,用户想输入偶数123456.
当用户输入数字时,你有:
1 => ;奇数
12 =>甚至
123 =>奇数
1234 =>甚至
12345 =>奇数
123456 =>甚至
你什么时候点击你的按钮?
想象一下用户想要输入偶数246.
当用户输入数字时,您有:
2 =>甚至
24 =>甚至
246 =>甚至
你什么时候点击你的按钮?
这种情况是为什么点击按钮留给用户的原因。
I want to press the Button in case if the number entered in edit control box is even.
I am new to MFC Dialog based application visual studio 2015.
Need Help
What I have tried:
I want to press the Button in case if the number entered in edit control box is even. I am new to MFC Dialog based application visual studio 2015. Need Help
- Get the integer, say
n
, from the edit box.- Check is
n
is even, namely:bool is_even = (n % 2 == 0);
- Call the button code (I would put it in a separate method say
DoMyWonderfulAction
and then call it appropriately both from code and the button).
Please note, there are several ways to implement point1
. If the edit box is already mapped to an integer variable (theUpdateData
mechanism), the better. Otherwise you have to get the string (e.g. viaGetWindowText
method) and then parse it (for instance, via _ttoi[^]) in order to get the integer value.
Quote:yes i want to click the button from code.
if variable entered in edit control box is even then button get clicked.
This is a bad idea !
Imagine the user want to enter the even number 123456.
As the user type the number, you have:
1 => odd
12 => even
123 => odd
1234 => even
12345 => odd
123456 => even
When do you click your button ?
Imagine the user want to enter the even number 246.
As the user type the number, you have:
2 => even
24 => even
246 => even
When do you click your button ?
This kind of situation is the reason why clicking on button is left to user.
这篇关于如果编辑控制框中输入的数字是偶数,如何按下按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!