StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Displaying a "hint" in a textboxExpand / Collapse
Author
Message
Posted 01/20/2010 7:55:25 PM
Strategic Support Team Member

Strategic Support Team Member

Group: StrataFrame Developers
Last Login: Yesterday @ 6:46:55 PM
Posts: 1,880, Visits: 5,732
Derek Price posted an enhancement suggestion (http://forum.strataframe.net/FindPost25576.aspx) about how to have a text box display a "hint" to the user if it had no current value and didn't have the focus.

I thought that it might be easy to just override the OnPaint method and if the text box had no value (Text property was empty), just render the hint text. This turned out to be not so easy to do. However, after beating my head against the desk for a couple of hours, I got that method to work (I'm stubborn that way). While I don't think this is a great solution (Les Pinter's solution is better I think), if you ever decide to do a bit of rendering yourself, this project might help.

The important details (detailed in comments in project) is that:

1. You either let .NET render the TextBox completely, or you do it yourself, completely. I.e. You can't call the base class OnPaint to get the basics done, then add a bit of flair. OnPaint is not called at all unless you use the SetStyle(ControlStyles.UserPaint, true), which turns on user rendering.

2. SF handles rendering if the text box is disabled, but not if it is enabled. This means that you can't really call the base OnPaint either, as it is only designed to be called if the control is disabled.

The result is that the OnPaint is pretty complex as it now must handle disabled/enabled rendering differences, themes, password characters and our new hint feature on top of the standard background and text rendering needed. There must also be overrides on several other methods in order to ensure that the control always does the rendering and to handle the rendering of the hint only when the control doesn't have the focus. See the project for details.

While I doubt I'd use this as is, I sure learned a lot about rendering and hope it helps someone else!



  Post Attachments 
HintTextBoxExample.zip (58 views, 27.24 KB)
Post #25587
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Trent L. Taylor, Dustin Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 8:34am

Powered by InstantForum.NET v4.1.4 © 2010
Execution: 0.078. 11 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.