delphi 在TEdit中显示水印提示


本文整理自网络,侵删。

 
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
unit MyEdit;

interface

uses Messages, Classes, StdCtrls, Controls, Graphics;

type
  TMyEdit = class(TEdit)
  private
    FCanvas: TControlCanvas;
    FWatermarkHint: string;
  protected
    procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
    procedure CMExit(var Message: TCMExit); message CM_EXIT;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property WatermarkHint: string read FWatermarkHint write FWatermarkHint;
  end;

implementation

{ TMyEdit }

procedure TMyEdit.CMExit(var Message: TCMExit);
begin
  inherited;
  Perform(WM_PAINT, 0, 0);
end;

constructor TMyEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FCanvas := TControlCanvas.Create;
  FCanvas.Control := Self;
end;

destructor TMyEdit.Destroy;
begin
  FCanvas.Free;
  inherited;
end;

procedure TMyEdit.WMPaint(var Message: TWMPaint);
begin
  inherited;
  if (not Focused) and (Self.Text = '') and (FWatermarkHint <> '') then
  begin
    FCanvas.Font := Self.Font;
    FCanvas.Font.Color := clGrayText;
    FCanvas.TextRect(Self.ClientRect, 1, 1, FWatermarkHint);
  end;
end;

end.

相关阅读 >>

Delphi xe更改ttrayicon系统任务栏图标(无模糊)

Delphi文件无法拖拽功能失效

Delphi驱动开发研究第一篇--实现原理

Delphi hmac256

Delphi打印各类文档

Delphi获取ie浏览器url地址

postmessage和sendmessage的区别

Delphi 备份恢复剪切板

Delphi win32_diskdrive 硬盘 参数说明

Delphi 阿里云发送短信的Delphi单元

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...