C#自定義實現密碼輸入掩碼效果方案,取代Microsoft.VisualBasic的Interaction無法實現inputbox輸入框獲取用戶內容時*星號
當前位置:點晴教程→知識管理交流
→『 技術文檔交流 』
在C#中使用 方案:創建自定義密碼輸入窗體
代碼實現:csharp
復制 // 自定義密碼輸入對話框窗體 public partial class PasswordInputDialog : Form { public string Password { get; private set; } public PasswordInputDialog(string prompt, string title) { InitializeComponent(); this.labelPrompt.Text = prompt; this.Text = title; } private void btnOK_Click(object sender, EventArgs e) { Password = textBoxPassword.Text; DialogResult = DialogResult.OK; Close(); } private void btnCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } // 在主程序窗口中,使用自定義對話框獲取輸入 public static string GetPasswordInput(string prompt, string title) { using (var dialog = new PasswordInputDialog(prompt, title)) { return dialog.ShowDialog() == DialogResult.OK ? dialog.Password : string.Empty; } } // 調用示例 string password = GetPasswordInput("請輸入密碼:", "密碼輸入"); 使用說明
優點
結論若必須使用原生 效果如下:
該文章在 2025/4/11 17:21:23 編輯過 |
關鍵字查詢
相關文章
正在查詢... |