Click here to Skip to main content
15,884,176 members
Articles / Desktop Programming / MFC
Tip/Trick

CEdit - Show or Hide Password

Rate me:
Please Sign up or sign in to vote.
4.24/5 (8 votes)
13 Feb 2016CPOL 16.9K   2   5
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:

C++
// ... 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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionFeedback acknowledged: Pin
JPhelps18-Feb-16 3:11
JPhelps18-Feb-16 3:11 
AnswerRe: Feedback acknowledged: Pin
Shao Voon Wong17-Jan-21 20:00
mvaShao Voon Wong17-Jan-21 20:00 
Question[My vote of 1] just a school exercise? Pin
Victor Nijegorodov16-Feb-16 7:10
Victor Nijegorodov16-Feb-16 7:10 
AnswerRe: [My vote of 1] just a school exercise? Pin
Damir Valiulin17-Feb-16 9:03
Damir Valiulin17-Feb-16 9:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.