yuswaroengsoftware Blog’s Delphi Tutorial
Contoh program menambahkan event.
nit ColorBox;
interface
uses
Classes, Graphics, Controls, Windows;
type
TOnLeftBoxClick = procedure(Sender: TObject) of object;
TOnRightBoxClick = procedure(Sender: TObject) of object;
TColorBox = class(TGraphicControl)
private
FRgnL, FRgnR: TRect;
FOnLeftBoxSelect: TOnLeftBoxClick;
FOnRightBoxSelect: TOnRightBoxClick;
protected
procedure Paint; override;
procedure MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnBoxLClick: TOnLeftBoxClick
read FOnLeftBoxSelect write FOnLeftBoxSelect;
property OnBoxRClick: TOnRightBoxClick
read FOnRightBoxSelect write FOnRightBoxSelect;
end;
procedure Register;
implementation
constructor TColorBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Height:=33;
Width:=61;
end;
destructor TColorBox.Destroy;
begin
inherited Destroy;
end;
procedure TColorBox.Paint;
var cp: Integer;
begin
with Canvas do
begin
Pen.Color:=clBtnHighlight;
MoveTo(0, Height-1); LineTo(0, 0); LineTo(Width-1, 0);
Pen.Color:=clBtnShadow;
LineTo(Width-1, Height-1); LineTo(1, Height-1);
end;
cp:=Width div 2;
{–left area–}
FRgnL.TopLeft:=Point(4, 4);
FRgnL.BottomRight:=Point(cp-1, Height-3);
{–right box–}
FRgnR.TopLeft:=Point(cp+1, 4);
FRgnR.BottomRight:=Point(Width-4, Height-4);
{–left box–}
Canvas.Brush.Color:=$00B7CAF7;
Canvas.Rectangle(4, 4, cp-1, Height-4);
{–right box–}
Canvas.Brush.Color:=$00F4D5C1;
Canvas.Rectangle(cp+1, 4, Width-4, Height-4);
end;
procedure TColorBox.MouseUp(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var p: TPoint;
begin
inherited MouseUp(Button, Shift, X, Y);
if Button <> mbLeft then Exit;
p:=Point(X, Y);
if PtInRect(FRgnL, p) then {–left box–}
begin
if Assigned(FOnLeftBoxSelect) then FOnLeftBoxSelect(Self);
Invalidate;
end
else if PtInRect(FRgnR, p) then {–right box–}
begin
if Assigned(FOnRightBoxSelect) then FOnRightBoxSelect(Self);
Invalidate;
end;
end;
procedure Register;
begin
RegisterComponents(’Demo’, [TColorBox]);
end;
end.
prosedur pembatasan gerakan mouse.
procedure TForm1.FormMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
R:=Rect(Left, Top, Left+Width, Top+Height);
if GerakDalamForm then ClipCursor(@R)
else ClipCursor(@NilaiDefault);
end;
Cara Gampang Mengakses Array
var
MyArray : Array[2..11] of integer;
Position : integer;
begin
for Position := Low(MyArray) to High(MyArray) do
MyArray[Position] := 0;
end;
0 comments:
Post a Comment
Leave Your Comment Here!