Movatterモバイル変換


[0]ホーム

URL:


Wayback Machine
10 captures
07 Jan 2008 - 15 Nov 2024
AprJANNov
Previous capture05Next capture
200920122013
success
fail
COLLECTED BY
Organization:Alexa Crawls
Starting in 1996,Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to theWayback Machine after an embargo period.
Collection:Alexa Crawls
Starting in 1996,Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to theWayback Machine after an embargo period.
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20120105204129/http://www.codeproject.com:80/KB/edit/XEditPrompt.aspx
Click here to Skip to main content
8,386,176 members and growing!
EmailPassword Lost password?
Home
Search within:




Licence CPOL
First Posted 5 Jul 2007
Views 37,712
Downloads 496
Bookmarked 51 times

XEditPrompt - CEdit-derived control with web-like prompt

ByHans Dietrich | 20 Jul 2007
XEditPrompt implements an edit control with built-in prompt and text color, just like you see on web pages.
 
See Also
Print Article
add
Add to your CodeProject bookmarks
Discuss
Discuss this article
12
  4.87 (23 votes)
1 vote, 4.3%
1

2

3
3 votes, 13.0%
4
19 votes, 82.6%
5
4.87/5 - 23 votes
1 removed
μ 4.82, σa 1.56 [?]
Sponsored Links

Introduction

TheXEditPromptcontrol is based onCEdit and mimics effect seen on web pages, where the text input field will have some initial text (like <Enter text here>), that will disappear as soon as the user clicks on that field.

How It Works

InitiallyXEditPromptwill display predefined prompt string, using predefined prompt color (both prompt string and color may be changed programmatically):

screenshot

When user action causesXEditPromptto gain focus, the initial prompt string is removed:

screenshot

The standard system colors such asCOLOR_GRAYTEXT andCOLOR_3DDKSHADOW are very light, so I chose RAL color for prompt text:

screenshot

Implementation Details

The API forXEditPromptis very simple, since its only properties are prompt text and color, plus function to reset state of the control:

// Operationspublic:void Reset();// Attributespublic:    COLORREF  GetPromptColor()   {return m_crPromptColor; }    CString   GetPromptText()    {return m_strPromptText; }void      SetPromptColor(COLORREF crText);void      SetPromptText(LPCTSTR lpszPrompt);

How To Use

To integrateCXEditPrompt class into your app, you first need to add the following files to your project:

  • XEditPrompt.cpp
  • XEditPrompt.h

Next, include header fileXEditPrompt.h in the appropriate project files (usually, this will be in the header file for dialog class). Then replace declaration ofCEdit control with this:

    CXEditPrompt   m_MyEdit;

(use whatever variable name already exists).

Now you are ready to start usingCXEditPrompt. In dialog'sOnInitDialog() function, insert line:

    m_MyEdit.SetPromptText(_T("<This is my special prompt>"));

Other Implementations

  • Prompting user for values from a CEdit by Tanzim Husain.
  • SetCueBanner() in Win2000, XP, and Vista allows you to set a prompt for a standardCEdit. The main differences betweenSetCueBanner() and my implementation is that it has a persistent prompt that keeps popping up until you actually enter some text, and the color of the prompt text cannot be changed.SetCueBanner() is available in Win2000 and later. According to MSDN, it is unsupported in Win98/ME.

Revision History

Version 1.1 � 2007 July 21

  • Changed tabbing behavior. Some people have said to me that just tabbing to an edit box should not cause the prompt to be removed - only direct action by user, like mouse click or keypress, since you may be hitting tab several times to get to another input control, and along the way erase the edit prompt. In this release, the edit prompt will no longer be removed by tabbing.
  • Added example ofSetCueBanner() to the demo app.

Version 1.0 � 2007 July 5

  • Initial public release

Usage

This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

License

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

About the Author

Hans Dietrich

Software Developer (Senior)
Hans Dietrich Software
United States United States

Member
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.
 
Recently, I have moved to Los Angeles where I am doing consulting and development work.
 
For consulting and custom software development, please seewww.hdsoft.org.







loading...
Sign Up to vote  PoorExcellent
Add a reason or comment to your vote:x
Votes of 3 or less require a comment

Comments and Discussions

 
 RefreshFirstPrevNext
GeneralSuggest adding GetWindowTextLengthmemberGraham Shanks13:00 23 Nov '08  
GeneralHandling disabled and read only states [modified]memberGraham Shanks7:10 6 Nov '08  
GeneralRegaining the promptmemberGraham Shanks7:37 27 Oct '08  
GeneralRe: Regaining the promptmembermolsson842:19 14 Apr '11  
AnswerRe: Regaining the promptmentorHans Dietrich2:33 14 Apr '11  
GeneralSetCueBanner can't workmemberbanbanyy19:02 14 May '08  
GeneralSetCueBanner()memberRavi Bhavnani4:05 6 Jul '07  
GeneralRe: SetCueBanner()membermykel5:45 6 Jul '07  
GeneralRe: SetCueBanner()memberNacereddine4:49 10 Jan '09  
GeneralLooks great... one suggestionmembermykel23:27 5 Jul '07  
GeneralRe: Looks great... one suggestionmvpHans Dietrich1:13 6 Jul '07  
GeneralVery nicememberBhaskarPriya22:06 5 Jul '07  
Last Visit: 19:00 31 Dec '99     Last Update: 10:27 5 Jan '121

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

Permalink |Advertise |Privacy |Mobile
Web02 |2.5.120104.1 |Last Updated 21 Jul 2007
Article Copyright 2007 by Hans Dietrich
Everything elseCopyright ©CodeProject, 1999-2012
Terms of Use
Layout:fixed|fluid

See Also...
The Daily Insider

[8]ページ先頭

©2009-2025 Movatter.jp