【问题标题】:Password Char matching user input [duplicate]密码字符匹配用户输入[重复]
【发布时间】:2019-04-03 20:38:06
【问题描述】:

此代码假定为添加到输入变量的每个数字添加一个字符“*”。每次单击按钮时,它都应在文本框中添加一个 *。它适用于第一个,但之后每次都会加倍。任何建议改变什么?

 String input;
        public Form1()
        {
            InitializeComponent();
        }



        private void Form1_Load(object sender, EventArgs e)
        {
            //Security Code variables
            securityCodeTextBox.Text = "";
            securityCodeTextBox.PasswordChar = '*';
            securityCodeTextBox.MaxLength = 5;

            securityCodeTextBox.PasswordChar = '*';            
            accessLogBox.Text += input;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.accessLogBox.Text = "";
            input += 1;
            this.securityCodeTextBox.Text  += input;
            this.accessLogBox.Text += input;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.accessLogBox.Text = "";
            input += 2;
            this.securityCodeTextBox.Text += input;
            this.accessLogBox.Text += input;
        }

【问题讨论】:

  • 你为什么要+= 1到一个字符串变量?
  • 这是一个 WinForms 文本框吗?他们已经通过 TextBox.PasswordChar 属性支持这一点。
  • 这不是他寻求@DourHighArch 帮助的原因,所以这不是重复的。

标签: c# char passwords


【解决方案1】:

每次单击按钮时,都会将一个数字附加到 input,然后将 input 附加到 Text。所以Text 的增长速度比input 的“更快”。

所以每个按钮(比如说button1)点击你会得到类似的东西:

1->11->111->1111
1->111->111111->1111111111 等等

好像你想要...Text=input 而不是...Text+=input

【讨论】:

  • @JeffRyan。如果这回答了您的问题(我相信它与您之前发布的一样),请将我的回答标记为答案(左侧的复选框),以便将来可能遇到类似问题的用户轻松查看解决您问题的方法。
猜你喜欢
  • 2015-09-10
  • 2017-08-15
  • 2014-06-21
  • 2011-10-21
  • 2021-04-10
  • 1970-01-01
  • 2013-03-25
  • 2018-12-07
  • 2020-10-26
相关资源
最近更新 更多