我如何填充默认文本的空文本框? [英] How do I fill an empty textbox with default text?

查看:288
本文介绍了我如何填充默认文本的空文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何填充文本的文本框,如果它是空的?我使用VB.NET。

How do I fill a textbox with text if it is empty? I am using VB.NET.

推荐答案

它看起来像你描述的提示横幅,这是显示在一个空的文本框提示文字。如Windows XP中的,此功能本身由操作系统支持。实现做这种方式的效果是不是设置了框TextChanged 事件的默认文本自己更优雅。它看起来是这样的:

It looks like you're describing a cue banner, which is prompt text that is displayed in an empty textbox. As of Windows XP, this functionality is natively supported by the operating system. The effect achieved doing it this way is much more elegant than setting the default text yourself in the TextChanged event. It looks like this:

     

     

设置此功能是通过发送文本框控件的 <$ C实现在Windows API的级别$ C> EM_SETCUEBANNER 消息。要使用这个从.NET项目,你将不得不使用的P / Invoke。

Setting this up is accomplished at the level of the Windows API by sending the textbox control an EM_SETCUEBANNER message. To use this from a .NET project, you will have to use P/Invoke.

幸运的是,大部分的工作已经为你做。 此示例项目是一个快速,无痛的方式来增加提示横幅支持现有的项目。 <一href="http://www.ageektrapped.com/blog/the-missing-net-1-cue-banners-in-windows-forms-em_setcuebanner-text-prompt/">Here's另一个样品时,与该过程的更完整的解释。

Fortunately, most of the work has already been done for you. This sample project is a quick and painless way to add cue banner support to an existing project. Here's another sample, with a more complete explanation of the process.

如果您不希望您的应用程序依赖于外部DLL,您可以直接添加必要的code到项目中。最简单的方法是继承现有的文本框控件,并添加code支持提示标语在那里。请参见这个答案为code,你将需要。如果您无法将其转换为VB.NET,尝试这个工具

If you don't want your application to depend on an external DLL, you can add the necessary code directly to your project. The simplest way is to subclass the existing TextBox control, and add the code to support cue banners there. See this answer for the code you'll need. If you have trouble converting it to VB.NET, try this tool.

这篇关于我如何填充默认文本的空文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆