Şifre İçin Maskeli InputBox Kullanımı | C#

Merhaba, C# ile geliştirdiğim bir uygulamada InputBox’a ihtiyacım oldu.
Bunun için Microsoft.VisualBasic referansını projemize eklememiz gerekiyor.

		using Microsoft.VisualBasic;

		string input = Interaction.InputBox("Prompt", "Title", "Default", x_coordinate, y_coordinate);

Ancak ekrandan alacağım değer bir şifre olduğundan bunun maskeli olarak gözükmesi gerekiyordu.
Bununla ilgili bir örnek buldum ve kendi projeme aşağıdaki şekilde uyarladım:

        string input = SifreInputBoxGetir("Lütfen şifrenizi giriniz: ");

        public static string SifreInputBoxGetir(string Prompt)
        {
            Form frmInput = new Form()
            {
                Size = new Size(150, 110),
                FormBorderStyle = FormBorderStyle.FixedDialog,
                MaximizeBox = false,
                MinimizeBox = false,
                Text = Prompt
            };
            Button btn = new Button()
            {
                Text = "OK",
                Location = new Point(40, 40),
                Width = 80                
            };
            btn.Click += inputclose;
            TextBox txtbox = new TextBox()
            {
                Width = 110,
                Location = new Point(10, 10),
                PasswordChar = '*'
            };
            frmInput.Controls.Add(btn);
            frmInput.Controls.Add(txtbox);
            frmInput.ShowDialog();
            return txtbox.Text;
        }

        public static void inputclose(object s, EventArgs e)
        {
            ((Form)(((Control)s).Parent)).Close();
        }

Selamlar.

Leave a Reply

Your email address will not be published. Required fields are marked *