如果编辑控制框中输入的数字是偶数,如何按下按钮 [英] How to press the button in case if the number entered in edit control box is even

查看:84
本文介绍了如果编辑控制框中输入的数字是偶数,如何按下按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在编辑控制框中输入的数字是偶数,我想按下按钮。

我是基于MFC Dialog的应用程序visual studio 2015的新手。

需要帮助



我尝试过:



如果在编辑控制框中输入的数字是偶数,我想按下按钮。 
我是基于MFC Dialog的应用程序visual studio 2015的新手。
需要帮助

解决方案

  1. 从编辑框中获取整数,例如 n
  2. 检查 n 是偶数,即: bool is_even =(n%2 == 0);
  3. 调用按钮代码(我会把它放在一个单独的方法中)说 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

解决方案

  1. Get the integer, say n, from the edit box.
  2. Check is n is even, namely: bool is_even = (n % 2 == 0);
  3. 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 point 1. If the edit box is already mapped to an integer variable (the UpdateData mechanism), the better. Otherwise you have to get the string (e.g. via GetWindowText 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆