首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >消息框未显示消息

消息框未显示消息
EN

Stack Overflow用户
提问于 2010-11-25 21:19:07
回答 1查看 368关注 0票数 1

我已经编写了一组函数来验证表单中的文本框是否满足它们所需的字段需求,如下所示

私有空ValidateForm()

代码语言:javascript
复制
        {
        //Initialise the variables for validation check and call the related functions
        bool bisValidhost = ValidateHost();
        bool bisValidPassword = ValidatePassword();
        bool bisUsername = ValidateUsername();

        //If any of the entries is missing then show error message
        if(bisValidhost && bisValidPassword && bisUsername == false)
            {
            MessageBox.Show("This is not a Valid Entry!");                
            }         
        }


    /// <summary>
    /// This function validate the Required field need of txtHost.
    /// </summary>
    /// <returns></returns>
    private bool ValidateHost()
        {
        ErrorProvider errorProvider = new ErrorProvider();
        bool isValid = true;

        //If the txtHost is empty, show a message to user
        if(txtHost.Text == string.Empty)
            {
            errorProvider.SetError(txtHost, "Please enter the host address");
            isValid = false;
            }
        else
            errorProvider.SetError(txtHost, string.Empty);
        return isValid;
        }


    ///<summary>
    /// This function validate the Required field need of txtUsername.
    /// </summary>
    /// <returns></returns>
    /// </summary>
    /// <returns></returns>
    private bool ValidateUsername()
        {
        ErrorProvider errorProvider = new ErrorProvider();
        bool isValid = true;

        //If the txtUsername is empty, show a message to user
        if(txtUsername.Text == string.Empty)
            {
            errorProvider.SetError(txtUsername, "Please enter the Username");
            isValid = false;
            }
        else
            errorProvider.SetError(txtUsername, string.Empty);
        return isValid;
        }


    ///<summary>
    /// This function validate the Required field need of txtPassword.
    /// </summary>
    /// <returns></returns>
    /// </summary>
    /// <returns></returns>
    private bool ValidatePassword()
        {
        ErrorProvider errorProvider = new ErrorProvider();
        bool isValid = true;

        //If the txtPassword is empty, show a message to user
        if(txtPassword.Text == string.Empty)
            {
            errorProvider.SetError(txtPassword, "Please enter the Password");
            isValid = false;
            }
        else
            errorProvider.SetError(txtPassword, string.Empty);
        return isValid;
        }

但是它没有显示正确的消息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-25 21:22:25

我可能误解了你的IF结构

代码语言:javascript
复制
if(bisValidhost && bisValidPassword && bisUsername == false) 

但我觉得你想

代码语言:javascript
复制
if( ! ( bisValidhost && bisValidPassword && bisUsername ))

假设你的答案都是真的(即:有效),那么它就会解释为

代码语言:javascript
复制
if ( TRUE and TRUE and ( TRUE == FALSE ))

如果前两个选项中有一个是假的,而最后一个是ok的,那么您应该

代码语言:javascript
复制
IF ( FALSE AND FALSE AND ( TRUE == FALSE))

通过执行逻辑NOT (!)检查它们中是否有任何一个失败是您想要的。

如果不是(3个部分都有效)

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4277472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档