for Loop Skipped

时间:2016-06-17 04:16:34

标签: c++ winforms for-loop

背景信息(你应该阅读): 我正在登录(用户名/密码)程序。我试图通过向上移动窗口成功登录直到它到达屏幕外来添加动画。

问题: 我为此使用了for循环,但我的程序似乎跳过了for循环。

我如何知道问题: 我知道因为我在for循环的内部和外部使用了OutputDebugStringW,它只在for循环之外输出。

对于循环代码:

            int LocationX = this->Location.X;
            int LocationY = this->Location.Y;
            if (this->passwordtbox->Text == L"password"){
                this->invalid->Text = L"Logging in...";
                for (int i = this->Location.Y; i <= -400; i--){
                    LocationY = LocationY - 1;
                    this->Location = Point(LocationX, LocationY);
                }

            }

EDIT 6/16/2016 9:17 PM:

名为“invalid”的标签应该显示程序的状态,如“无效的用户名/密码”或“登录...”

编辑2016年6月16日下午9:22: 解决了,最大的facepalm错误

1 个答案:

答案 0 :(得分:1)

您的不平等应该是>=,而不是<=,所以这样:

for (int i = this->Location.Y; i >= -400; i--){

您以正数(this->Location.Y)开头,因此永远不会满足i <= -400

相关问题