هذه مجموعة من الأكواد التي عثرت عليها وأحببت مشاركتكم بها
هذا كود لإنشاء فورم بزوايا مستديرة
procedure TForm1.FormCreate(Sender: TObject); var rgn: HRGN; begin Form1.Borderstyle := bsNone; rgn := CreateRoundRectRgn(0,// x-coordinate of the region's upper-left corner 0, // y-coordinate of the region's upper-left corner ClientWidth, // x-coordinate of the region's lower-right corner ClientHeight, // y-coordinate of the region's lower-right corner 40, // height of ellipse for rounded corners 40); // width of ellipse for rounded corners SetWindowRgn(Handle, rgn, True); end;
وهذا كود لعمل فتحة مضلعة في الفورم
type PtsType = array [0..15, 0..1] of Integer;</P> const Pts: PtsType = ((0, 0), (800, 0), (800, 600), (200, 600), (200, 220), (300, 280), (265, 205), (350, 117), (205, 170), (120, 90), (130, 200), (60, 350), (200, 220), (200, 600), (0, 600), (0, 0));</P> procedure TForm1.Button1Click(Sender: TObject); var HRegion1: THandle; begin HRegion1 := CreatePolygonRgn(Pts, SizeOf(Pts) div 8, alternate); SetWindowRgn(Handle, HRegion1, True); end;
وهذا كود لتلوين الخلفية في تطبيق MDI
private
{ Private declarations }
FClientInstance: TFarProc;
FPrevClientProc: TFarProc;
BkBrush: HBRUSH;
procedure ClientWndProc(var Message: TMessage);</P>
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
ثم
constructor TForm1.Create(AOwner: TComponent);
begin
inherited;
BkBrush := CreateSolidBrush(clblue);
FClientInstance := Classes.MakeObjectInstance(ClientWndProc);
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle, GWL_WNDPROC, Longint(FClientInstance));
end;</P>
destructor TForm1.Destroy;
begin
DeleteObject(BkBrush);
inherited;
end;</P>
procedure TForm1.ClientWndProc(var Message: TMessage);
var
DC: HDC;
BrushOld: HBRUSH;
begin
with Message do
begin
case Msg of
WM_ERASEBKGND:
begin
DC := TWMEraseBkGnd(Message).DC;
BrushOld := SelectObject(DC, BkBrush);
FillRect(DC, ClientRect, BkBrush);
SelectObject(DC, BrushOld);
Result := 1;
end;
else
Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
end;
end;
end;وهذا كود لعد مكونات من صنف واحد على الفورم
Function EditCount : Integer; var I , Y : Integer; begin Y := 0; for I := 0 to Form1.ComponentCount -1 do if Form1.Components is TEdit then Y := Y+1; result := Y; end;</P> procedure TForm1.Button1Click(Sender: TObject); begin Label1.Caption := 'Count of Edit is'+' '+InttoStr(EditCount) end;
وهذا كود مشابه ولكن لمعرفة اقام تسلسليةلمكون ما ضمن باقي المكونات
Function gotSeriatingNumber:Integer; var I : Integer; begin for I := 0 to Form1.ComponentCount -1 do if Form1.Components is TEdit then ShowMessage(IntToStr(I)); end;</P> procedure TForm1.Button1Click(Sender: TObject); begin gotSeriatingNumber; end;
