Click here to Skip to main content
13,150,178 members (30,875 online)
Click here to Skip to main content
Add your own
alternative version


44 bookmarked
Posted 21 Sep 2000

Dim Edit Control

, 28 Aug 2001
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! :)

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( <FONT color=#008000>COLOR_WINDOW</FONT> ) 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.


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


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(?):

You may also be interested in...


Comments and Discussions

GeneralNative Support On Windows XP... Pin
James R. Twine16-Mar-05 0:41
memberJames R. Twine16-Mar-05 0:41 
Generala minor improvement Pin
Franz Brunner22-Oct-04 23:54
memberFranz Brunner22-Oct-04 23:54 
GeneralCode Not Found Pin
Koundinya23-Dec-03 18:46
memberKoundinya23-Dec-03 18:46 
GeneralRe: Code Not Found Pin
James R. Twine24-Dec-03 1:10
memberJames R. Twine24-Dec-03 1:10 
GeneralRe: Code Not Found Pin
Koundinya24-Dec-03 1:13
memberKoundinya24-Dec-03 1:13 
GeneralRe: Code Not Found Pin
Koundinya24-Dec-03 1:15
memberKoundinya24-Dec-03 1:15 
GeneralRe: Code Not Found Pin
James R. Twine25-Dec-03 14:31
memberJames R. Twine25-Dec-03 14:31 
GeneralRe: Code Not Found Pin
Koundinya25-Dec-03 21:10
memberKoundinya25-Dec-03 21:10 
GeneralRe: Code Not Found Pin
Koundinya25-Dec-03 21:14
memberKoundinya25-Dec-03 21:14 
GeneralRe: Code Not Found Pin
James R. Twine27-Dec-03 15:40
memberJames R. Twine27-Dec-03 15:40 
GeneralDim function to a CComboBox Pin
elkhaze30-May-03 3:47
memberelkhaze30-May-03 3:47 
GeneralRe: Dim function to a CComboBox Pin
James R. Twine12-Jun-03 10:00
memberJames R. Twine12-Jun-03 10:00 
GeneralRe: Dim function to a CComboBox Pin
elkhaze8-Jul-03 9:51
memberelkhaze8-Jul-03 9:51 
General(D)HTML version... Pin
Eclypce25-Aug-01 16:07
memberEclypce25-Aug-01 16:07 
GeneralRe: (D)HTML version... Pin
James R. Twine27-Aug-01 4:34
memberJames R. Twine27-Aug-01 4:34 
GeneralRe: (D)HTML version... Pin
Terry Denham30-Aug-01 9:27
memberTerry Denham30-Aug-01 9:27 
GeneralThere 'ya go, Eclypce (Was: Re: (D)HTML version...) Pin
James R. Twine30-Aug-01 9:53
memberJames R. Twine30-Aug-01 9:53 
GeneralRe: (D)HTML version... Pin
Eclypce31-Aug-01 16:34
memberEclypce31-Aug-01 16:34 
GeneralRe: (D)HTML version... Pin
James R. Twine31-Aug-01 17:33
memberJames R. Twine31-Aug-01 17:33 
GeneralSource will be updated soon... Pin
James R. Twine22-Aug-01 14:32
memberJames R. Twine22-Aug-01 14:32 
GeneralIt has been updated. Pin
James R. Twine30-Aug-01 9:55
memberJames R. Twine30-Aug-01 9:55 

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.

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