从TextBox读取密码

时间:2012-05-05 07:04:59

标签: c# winforms

我在C#中创建了一个密码字段

 public System.Windows.Forms.TextBox passwordBox;

为此字段设置的其他设置为

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.CornflowerBlue;
            this.ClientSize = new System.Drawing.Size(381, 199);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.label1);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Progpassword";
            this.Text = "Programmer Password";
            this.TransparencyKey = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
            this.Load += new System.EventHandler(this.Progpassword_Load);
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

我无法读取在TextBox中输入的文字

我正在使用以下行

读取值
string text = PasswordBox.Text;

这是阅读密码字段的正确方法吗。

1 个答案:

答案 0 :(得分:1)

text = passwordBox.Text;只有这样你才能得到它!