CEdit - Show or Hide Password
To dynamically set the password viewing style for the edit control
Introduction
This code shows you how to dynamically change the edit control style specifically for the password feature..
Background
Being familiar with the CEdit
class would be useful.
Using the Code
I had a need to change the password style on an edit control dynamically. The following code shows how this can be done:
// ... where m_CtrlEditData is a CEdit control variable...
// On button click or other event/command - hide the input
m_CtrlEditData.SetPasswordChar('*');
m_CtrlEditData.Invalidate();
// On another button click or event/command - show the input
m_CtrlEditData.SetPasswordChar(0);
m_CtrlEditData.Invalidate();
Points of Interest
The call to Invalidate()
was necessary, otherwise you may simply not see any change.
SetPasswordChar
with a 0
, not a '0'
to show user input. In other words, SetPasswordChar('0')
does not work, but SetPasswordChar(0)
does work.
History
- Version 1.0