Disable password TextBox Caps-Lock is On warning

蓝咒 提交于 2020-07-10 05:36:46

问题


I am creating a login thing and I have this problem that every time I click on this "Show Password" Button and the Caps-Lock is activated, a Warning pops up and won't leave (at least I think it won't, which for the end-user would be even worse)

I would like to get rid of this warning completely.

Before redirecting my question to this question:
How to disable system's caps-lock notification on Textbox

I have already tried that.

Private Sub ShowPassword_MouseDown(sender As Object, e As MouseEventArgs) Handles ShowPassword.MouseDown
    If txt_Password.Text <> "" Then
        txt_Password.UseSystemPasswordChar = False

    End If
End Sub
Private Sub ShowPassword_MouseUp(sender As Object, e As MouseEventArgs) Handles ShowPassword.MouseUp
    If txt_Password.Text <> "" Then
        txt_Password.UseSystemPasswordChar = True
    End If
End Sub

The warning should disappear.
Hope this question can help other people other than just me. Edit: Thanks Jimi. :D


回答1:


When you do this:

[TextBox].UseSystemPasswordChar = [Bool Value]

the handle of the control is recreated each time (.Net source code)

The baloon tooltip will be shown for the new control handle, as soon as the TextBox.Text value changes: the tooltips will pile up.

A simple workaround - since disabling the warning may not be a good choice here - is to set the PasswordChar property to Char.MinValue or Nothing in the MouseDown handler of your Show Password Button, then set it back to the previous value on MouseUp. This won't recreate the handle (.Net Source code) and the balloon tooltip can be disabled pressing the Caps-Lock key.

Set UseSystemPasswordChar to False in the Designer.
In Form.Load or txt_Password.Enter: txt_Password.PasswordChar = ChrW(&H25CF)

Private Sub ShowPassword_MouseDown(sender As Object, e As MouseEventArgs) Handles ShowPassword.MouseDown
    txt_Password.PasswordChar = Char.MinValue
End Sub

Private Sub ShowPassword_MouseUp(sender As Object, e As MouseEventArgs) Handles ShowPassword.MouseUp
    txt_Password.PasswordChar = ChrW(&H25CF)
End Sub


来源:https://stackoverflow.com/questions/57199376/disable-password-textbox-caps-lock-is-on-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!