Texbox that is updated in real time

1

This is simple but I'm not sure how to do it:

The idea is to make a textbox inside a form in which if I enter a number this appears as '?' in the textbox.

My idea is to do it with the KeyPress event:

 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar < 48 || e.KeyChar > 59) && e.KeyChar != 8)
        {

        }
    }

Could someone tell me what to put in the "if" for this to work?

    
asked by FranciscoFJM 27.08.2017 в 01:58
source

2 answers

1

I solved it myself, but I still leave the solution in case someone needs it:

 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar > 47 && e.KeyChar < 60)
        {
            e.KeyChar = '?';
        }
    }

With this they will be able to enter any character calmly, but when they enter numbers they will be replaced with '?'.

    
answered by 27.08.2017 в 03:04
1

If you are working on Windows forms, you could have solved it like this:

  textBox1.PasswordChar = '?';

Greetings,

    
answered by 27.08.2017 в 17:20