Search code examples
winformspasswordsimemaskedtextboxchinese-locale

Chinese password in masked text box in Windows Forms?


When a Windows Forms TextBox is in password mode, it is restricted and the ImeMode is disabled (As discussed here and here). How can I design a textbox that doesn't reveal the user's input but that takes/collects the Chinese input from the keyboard (basically a workaround for taking in Chinese input in a password TextBox)?


Solution

  • You can use the OnKeyPress event to intercept input before it appears in the TextBox. Save the input somewhere else and put some masking char into the TextBox.

    private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        //save the key pressed
        TextBox1.Text += "*";
        e.handled = true;
    }