/
PasswordTextBoxDemoPanel.cs
41 lines (34 loc) · 1.46 KB
/
PasswordTextBoxDemoPanel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using FlagConsole.Controls;
using FlagConsole.Drawing;
namespace FlagConsole.Demo
{
public class PasswordTextBoxDemoPanel : Panel
{
private readonly Label _descriptionLabel;
private readonly Label _textLabel;
private readonly PasswordTextBox _passwordTextBox;
public PasswordTextBoxDemoPanel()
{
_descriptionLabel = new Label
{ Text = "Enter a password and press enter. The maximum length is set to 5 characters, but it has a width of 8. Of course, this limits can be increased." };
_descriptionLabel.Size = new Size(_descriptionLabel.Text.Length/3 + 1, 4);
Controls.Add(_descriptionLabel);
_passwordTextBox = new PasswordTextBox { Size = new Size(8, 1), MaxLength = 5, RelativeLocation = new Coordinate(0, 4) };
_passwordTextBox.TextSubmitted += PasswordTextBoxPasswordSubmitted;
Controls.Add(_passwordTextBox);
_textLabel = new Label { RelativeLocation = new Coordinate(0, 6) };
Controls.Add(_textLabel);
}
private void PasswordTextBoxPasswordSubmitted(object sender, EventArgs e)
{
_textLabel.Text = "You have entered: " + _passwordTextBox.Password;
_textLabel.Size = new Size(_textLabel.Text.Length, 1);
OnInvalidated(EventArgs.Empty);
}
public void Activate()
{
_passwordTextBox.Focus();
}
}
}