Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit EditGlaidson;
- interface
- uses
- System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, Vcl.Graphics,
- System.Types, Winapi.Windows, Winapi.Messages;
- type
- TEditGlaidson = class(TEdit)
- private
- { Private declarations }
- FIndent : integer;
- FCanvas : TCanvas;
- FRadiusValue: Smallint;
- procedure SetIndent(const Value:integer);
- procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
- protected
- { Protected declarations }
- procedure Paint; virtual;
- procedure WndProc(var Message: TMessage); override;
- procedure PaintWindow(DC: HDC); override;
- property Canvas: TCanvas read FCanvas;
- procedure RoundSquare;
- public
- { Public declarations }
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- { Published declarations }
- property RadiusValue: Smallint read FRadiusValue write FRadiusValue;
- property Indent: Integer read FIndent write SetIndent default 3;
- end;
- procedure Register;
- implementation
- procedure Register;
- begin
- RegisterComponents('EditdoGlaidson', [TEditGlaidson]);
- end;
- constructor TEditGlaidson.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FCanvas := TControlCanvas.Create;
- TControlCanvas(FCanvas).Control := Self;
- FIndent:=3;
- end;
- destructor TEditGlaidson.Destroy;
- begin
- FCanvas.Free;
- inherited Destroy;
- end;
- procedure TEditGlaidson.Paint;
- var
- IRec: TRect;
- begin
- inherited;
- RoundSquare;
- IRec := ClientRect;
- IRec.Left := IRec.Left + FIndent;
- IRec.Top := IRec.Top + 2;
- FCanvas.FillRect(ClientRect);
- FCanvas.Brush.Assign(Self.Brush);
- FCanvas.Font.Assign(Self.Font);
- DrawText(FCanvas.Handle, Self.Text, Length(Self.Text), IRec, DT_LEFT);
- end;
- procedure TEditGlaidson.SetIndent(const Value: Integer);
- begin
- if FIndent <> Value then
- begin
- FIndent := Value;
- Invalidate;
- end;
- end;
- procedure TEditGlaidson.PaintWindow(DC: HDC);
- begin
- inherited;
- FCanvas.Lock;
- try
- FCanvas.Handle := DC;
- try
- TControlCanvas(FCanvas).UpdateTextFlags;
- Paint;
- finally
- FCanvas.Handle := 0;
- end;
- finally
- FCanvas.Unlock;
- end;
- end;
- procedure TEditGlaidson.RoundSquare;
- var
- R : TRect;
- Rgn : HRGN;
- begin
- R := ClientRect;
- Rgn := CreateRoundRectRgn(R.Left, R.Top, R.Right, R.Bottom, FRadiusValue, FRadiusValue);
- Perform(EM_GETRECT, 0, lParam(@R));
- InflateRect(R, -5, -5);
- Perform(EM_SETRECTNP, 0, lParam(@R));
- SetWindowRgn(Handle, Rgn, True);
- Invalidate;
- end;
- procedure TEditGlaidson.WMPaint(var Message: TWMPaint);
- begin
- ControlState := ControlState+[csCustomPaint];
- inherited;
- ControlState := ControlState-[csCustomPaint];
- end;
- procedure TEditGlaidson.WndProc(var Message: TMessage);
- begin
- inherited;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement