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 )
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.
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.
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.
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:
- No characters typed
- 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.