For the complete documentation index, see llms.txt. This page is also available as Markdown.

PasswordBox

Introduction

The PasswordBox control is a TextBox-like control which can be used for entering passwords. It uses a SecureString rather than regular string and hides the entered characters by using the * key for each character typed. For more information see the SecureString documentation: https://learn.microsoft.com/en-us/dotnet/api/system.security.securestring?view=net-8.0

PasswordBox does not support the CTRL+C copy hotkey.

Code Example: Adding a PasswordBox

The following code adds a password box.

// Initialize
var passwordBox = new PasswordBox();
passwordBox.AddToRoot();
passwordBox.X = 50;
passwordBox.Y = 50;
passwordBox.Width = 200;
passwordBox.Height = 34;
passwordBox.Placeholder = "Enter Password";

var button = new Button();
button.AddToRoot();
button.X = 50;
button.Y = 90;
button.Text = "Get Password";
button.Click += (_, _) => button.Text = passwordBox.Password;

Try on XnaFiddle.NET

PasswordChar

The PasswordChar property can be used to customize the character that masks the actual text entered by the user. By default, this is an asterisk (*).

The following changes the PasswordChar:

Try on XnaFiddle.NET

Password entered in a PasswordBox

Last updated

Was this helpful?