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.

相关阅读 >>

关于公历与农历换算和时间处理的单元 calendar.pas

Delphi写一个简单的多线程的程序

Delphi 中拖动无边框窗口的5种方法

Delphi 四舍五入取整函数

Delphi copy 从字符串中复制指定范围中的字符

Delphi10.3通过json.serializers单元对大量数据序列化

Delphi 编写activex控件(ocx控件)的知识和样例

Delphi 比较两个位图是否相同

Delphi shgetfileinfo函数获取任何文件大图标

Delphi tstrings类的一些技巧

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



打赏

取消

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

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

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

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

评论

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