Public Class PasswordDialog Inherits Form Private lblPrompt As Label Private txtPassword As TextBox Private btnOK As Button Private btnCancel As Button Public ReadOnly Property PasswordText As String Get Return txtPassword.Text End Get End Property Public Sub New(prompt As String, title As String) Me.Text = title Me.FormBorderStyle = FormBorderStyle.FixedDialog Me.StartPosition = FormStartPosition.CenterParent Me.MaximizeBox = False Me.MinimizeBox = False Me.Width = 300 Me.Height = 150 lblPrompt = New Label() With { .Text = prompt, .AutoSize = True, .Left = 10, .Top = 10 } Me.Controls.Add(lblPrompt) txtPassword = New TextBox() With { .Left = 10, .Top = lblPrompt.Bottom + 10, .Width = 260, .UseSystemPasswordChar = True ' 关键:开启星号掩码 } Me.Controls.Add(txtPassword) btnOK = New Button() With { .Text = "确定", .DialogResult = DialogResult.OK, .Left = 110, .Top = txtPassword.Bottom + 15, .Width = 75 } Me.Controls.Add(btnOK) btnCancel = New Button() With { .Text = "取消", .DialogResult = DialogResult.Cancel, .Left = btnOK.Right + 10, .Top = txtPassword.Bottom + 15, .Width = 75 } Me.Controls.Add(btnCancel) Me.AcceptButton = btnOK Me.CancelButton = btnCancel End Sub Private Sub InitializeComponent() Me.SuspendLayout() ' 'PasswordDialog ' Me.ClientSize = New System.Drawing.Size(168, 25) Me.Name = "PasswordDialog" Me.ResumeLayout(False) End Sub Private Sub PasswordDialog_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class