VB6 文本框中的默认幻像标题
我怎样才能在VB6.0中做到这一点...
<块引用> <块引用>文本框中有一个默认的标题,当它为空时,比如说“在此处输入名称”。但是当用户填写时,标题将被替换...
How can I do this in VB6.0...
There's a default Caption in Textbox when it is empty, let say "Enter Name Here". but when the user fills in, the Caption will be replaced...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
本机 win32 替代方案:
这需要一个清单,因此以下内容保存为“
.exe.manifest
”(也可以使用资源)Native win32 Alternative:
This needs a manifest so the following saved as "
<exename>.exe.manifest
" (Can also use a resource)如果您希望在用户选择该框开始输入之前在文本框中使用默认值:
请使用文本框的 GotFocus() 事件并插入以下代码作为代码:
txtName.text = ""
in LostFocus() 事件使用:
if you want a default value in the textbox until a user selects the box to begin typing:
use the GotFocus() event for your textbox and insert the following as your code:
txtName.text = ""
in the LostFocus() event use:
Windows API 自此内置了提示横幅(或提示文本) Windows XP。 VB 6 并未直接公开它,但这并不妨碍您通过进行一些 API 调用来获取它。
与实现您自己的自定义样式相比,走这条路线有几个优点。一方面,它已经免费提供,这意味着您只需做很少的工作即可使用它。其次,它已经经过充分测试和专业打磨。第三,每当下一版本的Windows发布时,它都会自动升级。
您需要的所有代码都可以在这里找到:SendMessage:使用提示横幅提示用户
正如该页面所解释的,您需要确保您的 EXE 中包含了清单,以便您可以利用 Windows XP 主题和功能。该代码唯一真正棘手的部分是您需要确保传递 Unicode 字符串。
最终效果如下所示:
The Windows API has had cue banners (or prompt text) built in since Windows XP. It's not directly exposed by VB 6, but that doesn't stop you from getting at it by making a few API calls.
There are several advantages of going this route, versus implementing your own custom style. For one thing, it's already available for free, meaning you have to do very little work to use it. Second, it's already been fully tested and professionally polished. Third, it will automatically get upgrades whenever the next version of Windows comes out.
All the code you need is available here: SendMessage: Use Cue Banners to Prompt Users
As the page explains, you need to make sure that you've included a manifest with your EXE so that you can take advantage of the Windows XP themes and features. The only real tricky part about the code is that you need to make sure you pass a Unicode string.
The final effect looks something like this: