C#-TextBox-登入視窗密碼不可見---ShinePans
阿新 • • 發佈:2019-01-05
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace TextBox_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { textBox1.PasswordChar = '@'; //設定文字框的PasswordChar屬性為字元@ textBox2.UseSystemPasswordChar = true; //設定文字框的UseSystemPasswordChar屬性為True; } private void label1_Click(object sender, EventArgs e) { } } }
program.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace TextBox_1 { static class Program { /// <summary> /// 應用程式的主入口點。 /// </summary> [STAThread] static void Main() { //Enabled 獲取或設定一個值,該值指示控制元件是否可以對使用者互動做出響應 //ForeColor:獲取或設定控制元件的前景色 //Modifiers:指示TextBox控制元件的可見性級別 //Multiline://獲取或設定字元,該字元用於 //PasswordChar:獲取或設定字元 // :public char PasswordChar{get; set;} //ReadOnly:獲取或設定一個值,該值指示文字框中的文字是否為只讀 // :public bool ReadOnly{get ; set; } // :TextBox.ReadOnly=true; 將文字設定為只讀 //RightToLeft:獲取或設定一個值.該值指示是否將控制元件的元素對齊以支援使用從右向左的字型區域設定 //ScrollBars:獲取或設定哪些滾動條應出現在多行TextBox控制元件中 //Text:獲取或設定TextBox控制元件的文字 //UseSystemPasswordChar:獲取或設定一個值,該值指示TextBox控制元件中的文字是否應該以預設的密碼字元顯示 // :public Bool UseSystemPasswordChar{get ;set ;} //Visible:獲取或設定一個值,該值指示是否顯示該控制元件及其所有父控制元件 Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }
Form設計:
namespace TextBox_1 { partial class Form1 { /// <summary> /// 必需的設計器變數。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的資源。 /// </summary> /// <param name="disposing">如果應釋放託管資源,為 true;否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗體設計器生成的程式碼 /// <summary> /// 設計器支援所需的方法 - 不要 /// 使用程式碼編輯器修改此方法的內容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(155, 27); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(121, 21); this.textBox1.TabIndex = 0; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(155, 77); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(121, 21); this.textBox2.TabIndex = 1; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(66, 30); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(83, 12); this.label1.TabIndex = 2; this.label1.Text = "PassWordChar:"; this.label1.Click += new System.EventHandler(this.label1_Click); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(12, 80); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(137, 12); this.label2.TabIndex = 3; this.label2.Text = "UseSystemPassWordChar:"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(318, 151); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "登入"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; } }