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 webbrowser 使滚动条滚动到底部

Delphi qq表情的实现

Delphi tms web core js callproc

Delphi code无法回车换行

Delphi 如何使用通配符删除文件

Delphi把流中的字符串转换为utf格式

Delphi xe vcl - tlinklabel(链接标签)

Delphi 官方stylebook大全使用

Delphi删除文件

Delphi assignfile 与指定的文件建立连接

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



打赏

取消

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

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

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

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

评论

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