Delphi XE8: TEdit TextHint disappears when receiving focus

Basically, I want the TextHint of my TEdits to disappear when I enter the first character, and not when they get focus, for example Edits on this Microsoft page: Log in to your Microsoft account . Can someone please walk me through how to do this?

Thanks in advance.

+4
source share
2 answers

Based on Uwe Raabe's answer, here is the procedure (for Delphi 2007, should also work for newer versions of Delphi):

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;

You call it this way:

constructor TForm1.Create(_Owner: TComponent);
begin
  inherited;
  TEdit_SetCueBanner(ed_HideOnFocus, 'hide on focus', cbhHideOnFocus);
  TEdit_SetCueBanner(ed_HideOnText, 'hide on text', cbhHideOnText);
end;

It does not check the version of Windows, but you may need to add an ifwe statement:

if CheckWin32Version(5, 1) and StyleServices.Enabled and _ed.HandleAllocated then

I just tested it with a project where I turned off the runtime: it didn't work.

+2

TEdit , TEdit DoSetTextHint. , wParam 0 1.

, :

unit EditInterceptor;

uses
  Vcl.StdCtrls, System.SysUtils, Winapi.Messages, Windows;

type
  TEdit = class(Vcl.StdCtrls.TEdit)
  protected
    procedure DoSetTextHint(const Value: string); override;
  end;

implementation

uses
  Vcl.Themes, Winapi.CommCtrl;

procedure TEdit.DoSetTextHint(const Value: string);
begin
  if CheckWin32Version(5, 1) and StyleServices.Enabled and HandleAllocated then
    SendTextMessage(Handle, EM_SETCUEBANNER, WPARAM(1), Value);
end;

end.  

Vcl.StdCtrls.

+6

Source: https://habr.com/ru/post/1598967/


All Articles