This is a migrated thread and some comments may be shown as answers.

Password Textbox support similar to Android EditText

1 Answer 67 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Srivatsa
Top achievements
Rank 1
Srivatsa asked on 03 Jun 2015, 10:43 AM

Hello 

Does RadControls have a textbox where in I can implement a textbox password field similar to Android Environment. 

I should be able to enter a character, display the character entered for a few milliseconds before masking it using "asterix" or any other password

character. Also I should be able to edit/insert/delete any character anywhere in the content.

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Jun 2015, 02:02 PM
Hi Srivatsa,

Thank you for writing.

It is possible to achieve similar behavior with RadTextBoxControl. You can use a timer and replace the text with a password char after some time. You can save the password in a separate string and use the KeyDown and KeyPress events to synchronize the text. For example:
Timer timer;
string password;
 
public RadForm1()
{
    InitializeComponent();
    password = "";
    timer = new Timer();
    timer.Tick += timer_Tick;
    timer.Interval = 800;
 
    radTextBoxControl1.TextChanged += radTextBoxControl1_TextChanged;
    radTextBoxControl1.KeyPress += radTextBoxControl1_KeyPress;
    radTextBoxControl1.KeyDown += radTextBoxControl1_KeyDown;
}
 
void radTextBoxControl1_KeyDown(object sender, KeyEventArgs e)
{
    int caretIndex = radTextBoxControl1.CaretIndex;
 
    if (e.KeyCode == Keys.Back && caretIndex >= 0)
    {
        password = password.Remove(caretIndex, 1);
    }
}
 
void radTextBoxControl1_KeyPress(object sender, KeyPressEventArgs e)
{
    int caretIndex = radTextBoxControl1.CaretIndex;
    if (char.IsLetterOrDigit(e.KeyChar))
    {
        password = password.Insert(caretIndex, e.KeyChar.ToString());
    }
    radLabel1.Text = password;
}
 
void timer_Tick(object sender, EventArgs e)
{
    int caretIndex = radTextBoxControl1.CaretIndex;
    radTextBoxControl1.Text = new string('*', password.Length);
    radTextBoxControl1.CaretIndex = caretIndex ;
     
    timer.Stop();
}
 
void radTextBoxControl1_TextChanged(object sender, EventArgs e)
{
    if (timer.Enabled)
    {
        return;
    }
    timer.Start();
}

Please let me know if there is something else I can help you with.

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TextBox
Asked by
Srivatsa
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or