private
{ Private declarations }
public
{ Public declarations }
Edits: array[0..5] of TEdit;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
for i := 0 to 5 do
begin
Edits[i] := TEdit.Create(Self);
with Edits[i] do
begin
Parent := Self;
SetBounds(10, 10 + i*50, 200, 40);
Tag := i; //each control should remember its index
OnChange := EditChange; //same event handler for all controls
end;
end;
end;
procedure TForm1.EditChange(Sender: TObject);
var
i: integer;
begin
i := TEdit(Sender).Tag;
ShowMessage(Format('Anda menekan Edit[%d]',[i]));
end;
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
panel1.Perform(WM_SYSCOMMAND, $f012, 0)
end;
procedure TForm1.SetTransparent(hWnd: longint; value: byte);
var
style: integer;
begin
style := GetWindowLong(hWnd, GWL_EXSTYLE);
if value < 255 then
begin
style := style Or WS_EX_LAYERED;
SetWindowLong(hWnd, GWL_EXSTYLE, style);
SetLayeredWindowAttributes(hWnd, 0, value, LWA_ALPHA);
end else
begin
style := style xor WS_EX_LAYERED;
SetWindowLong(hWnd, GWL_EXSTYLE, style);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetTransparent(Handle, 200);
end;
procedure TForm1.SetTopmost(form: TForm; topmost: boolean);
begin
if topmost then
SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE)
else
SetWindowPos(form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetTopmost(form1, true);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
hSysMenu: HMENU;
begin
hSysMenu := GetSystemMenu(Handle, false);
EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND or MF_GRAYED);
end;
procedure TForm1.ShowTitlebar(AForm: TForm; bShow: boolean);
var
style: longint;
begin
with AForm do
begin
if BorderStyle = bsNone then exit;
style := GetWindowLong(Handle, GWL_STYLE);
if bShow then
begin
if (style and WS_CAPTION) = WS_CAPTION then exit;
case BorderStyle of
bsSingle, bsSizeable:
SetWindowLong(Handle, GWL_STYLE, style or WS_CAPTION or WS_BORDER);
bsDialog:
SetWindowLong(Handle, GWL_STYLE, style or WS_CAPTION or DS_MODALFRAME or
WS_DLGFRAME);
end;
end else
begin
if (style and WS_CAPTION) = 0 then exit;
case BorderStyle of
bsSingle, bsSizeable:
SetWindowLong(Handle, GWL_STYLE, style and (not(WS_CAPTION)) or WS_BORDER);
bsDialog:
SetWindowLong(Handle, GWL_STYLE, style and (not(WS_CAPTION)) or
DS_MODALFRAME or WS_DLGFRAME);
end;
end;
SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or
SWP_FRAMECHANGED or SWP_NOSENDCHANGING);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
rgn: HRGN;
begin
Form1.Color := clGreen;
Form1.BorderStyle := bsNone;
GetWindowRgn(Handle, rgn);
DeleteObject(rgn);
rgn:= CreateRoundRectRgn(0, 0, Width, Height, 100, 100);
SetWindowRgn(Handle, rgn, TRUE);
end;
procedure TForm1.FormCreate(Sender: TObject);
var wleft, wRight : word;
begin
wleft := 10;
wRight := 10;
Memo1.Perform(EM_SETMARGINS, EC_LEFTMARGIN or EC_RIGHTMARGIN, MAKELONG(wLeft, wRight));
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
Direction : Integer;
begin
Direction := -1;
case Key of
VK_DOWN,VK_RETURN : Direction := 0; {Next}
VK_UP : Direction := 1; {Previous}
end;
if Direction <> -1 then
begin
Perform(WM_NEXTDLGCTL, Direction, 0);
Key := 0;
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
var Row, Ht:Word;
begin
Ht := (ClientHeight + 255) div 256 ;
for Row := 0 to 255 do
with Canvas do begin
Brush.Color := RGB(0, 0, Row);
FillRect(Rect(0, Row * Ht,
ClientWidth, (Row + 1) * Ht)) ;
end;
end;