Come impostare un'immagine di sfondo per Edit (Delphi)
-
30-09-2019 - |
Domanda
Come posso avere un immagine di sfondo Editbox?
Soluzione
Questo è molto possibile, anzi. Nel modulo, definire
private
{ Private declarations }
FBitmap: TBitmap;
FBrush: HBRUSH;
protected
procedure WndProc(var Message: TMessage); override;
e fare
procedure TForm1.FormCreate(Sender: TObject);
begin
FBitmap := TBitmap.Create;
FBitmap.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\AS20Utv.bmp');
FBrush := 0;
FBrush := CreatePatternBrush(FBitmap.Handle);
end;
e
procedure TForm1.WndProc(var Message: TMessage);
begin
inherited;
case Message.Msg of
WM_CTLCOLOREDIT, WM_CTLCOLORSTATIC:
if (Message.LParam = Edit1.Handle) and (FBrush <> 0) then
begin
SetBkMode(Message.WParam, TRANSPARENT);
Message.Result := FBrush;
end;
end;
end;
Naturalmente si può avvolgere questo in un componente del proprio, diciamo TEditEx
. Se avrò tempo finito, potrei fare questo. (E, si noti che non v'è alcuna necessità di acquistare un costoso (e forse non così alta qualità) pacchetto componente da una società di terze parti).
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow