发布刚写的类似于大富翁全文检索中的Edit控件了(0分)

  • 主题发起人 主题发起人 一条大鱼
  • 开始时间 开始时间

一条大鱼

Unregistered / Unconfirmed
GUEST, unregistred user!
看见有人需要这样的控件
正好没事干,写一个,供大家学习,交流,完善
控件很简单,比较漏野,但还是能用的
哪个觉得不顺眼就改完善,发布上来大家共享

使用方法,新开一个单元,Copy下列代码覆盖,保存。剩下的步骤不用我说了吧
新增属性LineColor,LineWidth用于设置那条线的颜色和宽度
使用注意事项,不要去改变AutoSize、BorderStyle、ParentFont属性,否则就漏馅了,哈哈

代码如下:
unit LineEdit;

interface

uses
Messages, Windows, SysUtils, Classes, Controls, StdCtrls, Graphics, Forms;

type
TLineEdit = class(TEdit)
private
{ Private declarations }
FCanvas: TControlCanvas;
FLineColor: TColor;
FLineWidth: integer;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure SetLineColor(const Value: TColor);
procedure SetLineWidth(const Value: integer);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property LineColor:TColor read FLineColor write SetLineColor default clBlack;
property LineWidth:integer read FLineWidth write SetLineWidth default 1;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TLineEdit]);
end;

{ TLineEdit }

constructor TLineEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
BorderStyle:=bsNone;
ParentColor:=True;
AutoSize:=False;
FCanvas := nil;
end;

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

procedure TLineEdit.WMPaint(var Message: TWMPaint);
begin
inherited;
if FCanvas = nil then
begin
FCanvas := TControlCanvas.Create;
FCanvas.Control := Self;
end;
FCanvas.Pen.Color:=FLineColor;
FCanvas.Pen.Width:=FLineWidth;
FCanvas.MoveTo(0,Height-2);
FCanvas.LineTo(Width,Height-2);
end;

procedure TLineEdit.SetLineColor(const Value: TColor);
begin
if FLineColor<>Value then
begin
FLineColor := Value;
Invalidate;
end;
end;

procedure TLineEdit.SetLineWidth(const Value: integer);
begin
if (Value<0) or (Value>Height-3) then Exit;
if FLineWidth<>Value then
begin
FLineWidth:=Value;
Invalidate;
end;
end;

end.
 
不错啊[:D]
 
后退
顶部