Click here to Skip to main content
Click here to Skip to main content

Dim Edit Control

, 28 Aug 2001 CPOL
Rate this:
Please Sign up or sign in to vote.
An edit control that can provide visual cues in its text area.

This article describes a class (CDimEdit) for a "Dim Edit" control. I first saw the idea for a Dim Edit control in some (D)HTML code, a while back. The idea behind a Dim Edit control is that an input control can provide visual clues to how it should be used, like a Masked edit control. In the case of a Dim Edit control, the control can tell you what it is for, or that certain data is required or optional, rather than enforce the format of data.

This control is useful when you have to provide the user with a form-like interface, like a "request for more information" form on a web page. There might not be enough room on the interface to indicate with complete clarity that certain fields are required as opposed to optional. That is where this control can help.

The Dim Edit control will show some specified text (called Dim Text) centered in the edit control's visible area. This text is only visible while the control has no data within it. So when the user starts typing in the control, the Dim Text will be hidden. If the control becomes empty again, it gets shown again. The color of the Dim Text can also be specified.

This control is not a solution to every UI problem out there, but it sure beats the hell out of putting "*"s next to fields to indicate that they are required! Smile | :)

Functions of interest are:

  • void SetShowDimControl( bool bShow )
  • void SetDimText( LPCTSTR cpText )
  • void SetDimColor( COLORREF crDColor )
  • void SetDimOffset( char cRedOS, char cGreenOS, char cBlueOS )

The SetShowDimControl(...) function is used to override the automatic handling of showing/hiding the Dim Text. That being said, this function is not really that useful. There is no GetShowDimControl(...), because checking to see if the control has any text is (usually) good enough.

The SetDimText(...) function is used to set the string that will be displayed as Dim Text. In the .H file, there is a constant that determines the maximum length of the buffer used for storing the Dim Text. Adjust this value to your liking.

The SetDimColor(...) function is used to directly specify the color to be used when drawing the Dim Text. Take care when using this function to make sure that you are taking the user's current color settings into consideration.

The SetDimOffset(...) function is used to construct a color value based on the offsets applied. For example, with a normal GetSysColor( COLOR_WINDOW ) return value of white, an offset value of "-0x40" provides a nice grey color for the Dim Text.

In the demo image above, the numbered dialogs show the operation of the control before and after a Username was typed:

  1. No characters typed
  2. A Username was entered into the first control. The Dim Text is hidden after the first character is entered.

Conditions of use are detailed in the header and source file(s).

Feel free to contact me if there are any questions. Have fun.

License

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

Share

About the Author

James R. Twine
President JRTwine Software, LLC
United States United States
Programming since the age of 10, started professionally at the age of 17. Currently involved in both Client and Server side development on Win32 platforms for MC/HA/FT financial applications. Development experience with Win32, Win16, Linux and other flavors of Unix.
 
Extensive multithreaded development experience on Windows platforms using the Win32 SDK, and MFC.
 
Experience with HA/FT n-tiered Client/Server systems as well as GUI apps of varying complexity. Some experience with Game developement.
 
Having learned that the stuff you can barely get away with doing Client-side apps just does not cut it in the real "Server World", I am amazed how many 'professionals' cannot tell the difference between "works" and "correct" or try to (mis)use VB and/or MFC on server-side development projects, never considering that just because it RUNS, does not mean it runs WELL.
 
Lastly, I am also a collector of arcade games, and can perform repairs, conversions, etc. Search for my name, you will find me on lots of arcade-related documents and sites.
 
Sites of interest(?):
http://www.jrtwine.com
http://www.jrtwine.com/jtwine
http://www.signingtime.com
http://www.deletefxpfiles.com
http://www.checkfavorites.com
http://www.coinop.org

Comments and Discussions

 
GeneralNative Support On Windows XP... PinmemberJames R. Twine16-Mar-05 0:41 
Generala minor improvement PinmemberFranz Brunner22-Oct-04 23:54 
GeneralCode Not Found PinmemberKoundinya23-Dec-03 18:46 
GeneralRe: Code Not Found PinmemberJames R. Twine24-Dec-03 1:10 
GeneralRe: Code Not Found PinmemberKoundinya24-Dec-03 1:13 
GeneralRe: Code Not Found PinmemberKoundinya24-Dec-03 1:15 
GeneralRe: Code Not Found PinmemberJames R. Twine25-Dec-03 14:31 
GeneralRe: Code Not Found PinmemberKoundinya25-Dec-03 21:10 
GeneralRe: Code Not Found PinmemberKoundinya25-Dec-03 21:14 
GeneralRe: Code Not Found PinmemberJames R. Twine27-Dec-03 15:40 
GeneralDim function to a CComboBox Pinmemberelkhaze30-May-03 3:47 
GeneralRe: Dim function to a CComboBox PinmemberJames R. Twine12-Jun-03 10:00 
GeneralRe: Dim function to a CComboBox Pinmemberelkhaze8-Jul-03 9:51 
General(D)HTML version... PinmemberEclypce25-Aug-01 16:07 
GeneralRe: (D)HTML version... PinmemberJames R. Twine27-Aug-01 4:34 
GeneralRe: (D)HTML version... PinmemberTerry Denham30-Aug-01 9:27 
GeneralThere 'ya go, Eclypce (Was: Re: (D)HTML version...) PinmemberJames R. Twine30-Aug-01 9:53 
GeneralRe: (D)HTML version... PinmemberEclypce31-Aug-01 16:34 
GeneralRe: (D)HTML version... PinmemberJames R. Twine31-Aug-01 17:33 
GeneralSource will be updated soon... PinmemberJames R. Twine22-Aug-01 14:32 
GeneralIt has been updated. PinmemberJames R. Twine30-Aug-01 9:55 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 29 Aug 2001
Article Copyright 2000 by James R. Twine
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid