【问题标题】:menustrip and custom message box菜单条和自定义消息框
【发布时间】:2013-11-22 01:32:03
【问题描述】:

我创建了一个自定义登录表单。当用户单击 menustrip 工具时,我会显示登录表单。如果他输入了正确的用户名和密码,我希望关闭并禁用此表单,并且 menustrip 上的工具将像 menustrip 中的任何正常工具一样正常激活,而不会再次显示此表单。

自定义登录表单的图片为:

当用户按下登录时,我想禁用表单并且即使用户再次按下该工具也不会再次显示。

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    您可能应该禁用菜单按钮。这是伪代码,接近真实 - 可以解决问题:

    bool _loggedOnALready;
    void menustripLogon_click()
    {
        // if you want to disable menu - use this block
        if (form.showdialog() == dialogresult.Ok)
        {
            menustripLogon.enabled = false;
        }
    
        // But if you want to be able to press the button but no form show:
        if (!_loggedOnALready && (form.showdialog() == dialogresult.Ok) )
        {
            _loggedOnALready = true;
        }
    
    }
    
    class formLogon
    {
        void Ok_click()
        {
            if (LogonSuccess())
            {
                this.dialogResult = dialogresult.Ok;
                this.close();
            }
            else
            {
                this.dialogResult = dialogresult.Cancel;
                // you probably want keep it open for retry
            }
        }
    
        bool LogonSuccess()
        {
            // logon here
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 1970-01-01
      • 2013-09-12
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多