PDA

View Full Version : توابع مینیمایز کردن فرم با استفاده از dll



baran_2005
سه شنبه 03 آذر 1388, 17:26 عصر
با سلام به همه اساتید
من توی dll یک label در زمان اجرا create می کنم و بعد می خواهم رویداد onclick ان را با رویداد onclick یک برچسب دیگر که از قبل در برنامه وجود دارد set کنم و کد زیر رو براش نوشتم .
LB_Min.OnClick:=tlabel(form1.FindComponent('LB_Tas k')).OnClick ;
اما زمانی که رو برچسب در برنامه کلیک میکنم هیچ اتفاقی نمی افته در حالی که اگر این کار رو در خود برنامه انجام بدم درست عمل می کند .
من این کار رو برای مینیمایز صفحاتم می خواهم انجام بدهم . که کد این دو تابع رو هم گذاشتم .

//--------------minimaize-------------------
procedure FormMinimize(Form:TForm;form1:tform);stdcall;
var LB_name,l:string;
LB_min:tlabel;
Title :string;
begin
Title:=tlabel(form.FindComponent('LB_Title')).Capt ion ;
LB_name:=Form.Name;
if Form.Hint ='A' then begin
LB_Min:=tlabel.Create(form1);
if TPanel(form1.FindComponent('PL_Min'))<>nil then begin
lb_min.ParentFont:=false;
LB_Min.Parent:=tpanel(form1.FindComponent ('PL_Min'));
LB_Min.Caption:=' << '+ title +' >>';
LB_Min.Font.Name:='Traffic';
LB_Min.Font.Size:=10;
LB_Min.Font.Style:=[fsBold];
LB_Min.Font.Color:=clWhite;
LB_Min.Align:=alLeft;
LB_Min.Color:=clred;
LB_Min.Cursor:=crHandPoint;
LB_Min.Name:=LB_name;
LB_Min.OnClick:=tlabel(form1.FindComponent('LB_Tas k')).OnClick ;
form.Hint:='B';
ShowWindow(form.Handle, SW_MINIMIZE ) ;
end;
end
else
form.Hint :='A';
form.Refresh ;
end;
//------------------ restore
procedure RestoreForm(application:TApplication ;sender:tobject); stdcall;
var i:integer;
form_name:string;
begin
if TForm(Application.FindComponent((Sender As TLabel).Name))<>nil then
form_name:= tform(application.FindComponent('form1')).FindComp onent( TLabel(Sender ).Name).Name ;
for i:= 1 to tform(application.FindComponent('form1')).Componen tCount-1 do begin
if tform(application.FindComponent('form1')).Componen ts [i].ClassNameIs ('tlabel') then
if tform(application.FindComponent (Form_name))<>nil then
ShowWindow(tform(application.FindComponent (Form_name)) .Handle, SW_RESTORE) ;

end;
end;

تابع اول میاد از داخل فرم برچسب lb_title رو پیدا میکنه و caption ان به عنوان caption برچسب مینیمایز شده داخل پنلی با عنوان pl_min قرار می دهد .
اگر راه بهتری هم دارین بگین ممنون میشم . (البته این دوتابع ناقص هستند فقط برای مینیمایز و بازگشت به حالت اول است و یکسری کد دیگه باید به انها اضافه شود )