C#自定義實現(xiàn)密碼輸入掩碼效果方案,取代Microsoft.VisualBasic的Interaction無法實現(xiàn)inputbox輸入框獲取用戶內(nèi)容時*星號
當前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
在C#中使用 方案:創(chuàng)建自定義密碼輸入窗體
代碼實現(xiàn):csharp
復(fù)制 // 自定義密碼輸入對話框窗體 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; } } // 調(diào)用示例 string password = GetPasswordInput("請輸入密碼:", "密碼輸入"); 使用說明
優(yōu)點
結(jié)論若必須使用原生 效果如下:
該文章在 2025/4/11 17:21:23 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |