【问题标题】:Password Character not working on System.Windows.Forms.TextBox密码字符在 System.Windows.Forms.TextBox 上不起作用
【发布时间】:2010-11-09 22:46:13
【问题描述】:

原来如此。

我正在使用 VS2008 Express。

所有示例都说只是设置 PasswordChar,但没有任何内容被屏蔽。

我也尝试设置“UseSystemPasswordChar”=true.. 不走运..

   // Set to no text.
   textBox1.Text = "";
   // The password character is an asterisk.
   textBox1.PasswordChar = '*';
   // The control will allow no more than 14 characters.
   textBox1.MaxLength = 14;

我使用 TextBox 的原因是因为我希望用户能够点击返回并提交数据。重要的是要注意我猜我有 MultiLine = true 以便我可以捕获返回。

我似乎无法使用 maskedTextBox 捕获返回。我得到的只是系统提示音。

任何一个的解决方案对我来说都很好!

【问题讨论】:

    标签: c# winforms textbox passwords maskedtextbox


    【解决方案1】:

    如果您阅读 the documentation 是说“如果 Multiline 属性设置为 true,则设置 PasswordChar 属性没有视觉效果。”

    【讨论】:

    • 您可能还感兴趣地注意到,您可以通过在设置为该按钮的表单上使用带有 AcceptButton 属性的 Button 在 Enter 上提交:msdn.microsoft.com/en-us/library/…
    【解决方案2】:

    当 Multiline 设置为 true 时,UseSystemPasswordChar 不起作用。即使 Multiline = false,标准的 Windows 窗体文本框也接受返回。

    解决方案:设置 Multiline = False,并在表单上设置一个按钮以使用 AcceptButton 属性,或者在文本框的“KeyPress”事件中捕获返回/回车键。

    【讨论】:

      【解决方案3】:

      当使用 maskedTextBox 时,捕获按键并执行以下操作:

      if ( e.KeyChar == 13) {
          /* This is the enter key. Do stuff. */
      }
      

      【讨论】:

        猜你喜欢
        • 2015-12-19
        • 2014-12-06
        • 2014-02-07
        • 2015-10-04
        • 1970-01-01
        • 1970-01-01
        • 2017-10-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多