Delphi XE8:TEdit TextHint在接收到焦点时消失 [英] Delphi XE8: TEdit TextHint Disappears When Receiving Focus
问题描述
基本上,当我们输入第一个字符时,我想要我的TEdits的TextHint消失,而不是当他们收到焦点时,就像这个Microsoft页面上的Edits一样:登录到您的Microsoft帐户。有人可以告诉我如何实现这一点吗?
Basically, I want the TextHint of my TEdits to disappear when the first character is entered and not when they receive focus, like the Edits on this Microsoft page: Sign in to your Microsoft account. Can someone please walk me through on how to achieve this?
提前谢谢。
推荐答案
根据Uwe Raabe的回答,这里是一个程序(适用于Delphi 2007,应该适用于较新版本的Delphi):
Based on Uwe Raabe's answer, here is a procedure (for Delphi 2007, should work for newer versions of Delphi as well):
type
TCueBannerHideEnum = (cbhHideOnFocus, cbhHideOnText);
procedure TEdit_SetCueBanner(_ed: TEdit; const _s: WideString; _WhenToHide: TCueBannerHideEnum = cbhHideOnFocus);
const
EM_SETCUEBANNER = $1501;
var
wParam: Integer;
begin
case _WhenToHide of
cbhHideOnText: wParam := 1;
else // cbhHideOnFocus: ;
wParam := 0;
end;
SendMessage(_ed.Handle, EM_SETCUEBANNER, wParam, Integer(PWideChar(_s)));
end;
你这样称呼:
constructor TForm1.Create(_Owner: TComponent);
begin
inherited;
TEdit_SetCueBanner(ed_HideOnFocus, 'hide on focus', cbhHideOnFocus);
TEdit_SetCueBanner(ed_HideOnText, 'hide on text', cbhHideOnText);
end;
虽然没有检查Windows版本,但您可能想添加if语句Uwe如果CheckWin32Version(5,1)和StyleServices.Enabled和_ed.HandleAllocated然后
$ c $,则
It doesn't check for the Windows version though, you might want to add the if statement Uwe provided:
if CheckWin32Version(5, 1) and StyleServices.Enabled and _ed.HandleAllocated then
我刚刚在一个项目中测试过,它禁用了运行时版本:它没有起作用。
I just tested it with a project where I disabled runtime theming: It didn't work.
这篇关于Delphi XE8:TEdit TextHint在接收到焦点时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!