![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
![]() Доброго дня!
Надеюсь на помощь.... Есть такой код: Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; GroupBox1: TGroupBox; Button5: TButton; Panel2: TPanel; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; procedure FormResize(Sender: TObject); procedure FormShow(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; w,h:integer; implementation {$R *.dfm} procedure TForm1.FormResize(Sender: TObject); var prw,prh:real;i:integer; begin prw:=form1.Width/w; prh:=form1.height/h; for i:=0 to form1.ComponentCount-1 do if (components[i] is tbutton) and (components[i] is tlabel) and (components[i] is TGroupBox) and (components[i] is tpanel) then begin (components[i] as tbutton).Left:=round((components[i] as tbutton).Left*prw); (components[i] as tbutton).top:=round((components[i] as tbutton).top*prh); (components[i] as tbutton).width:=round((components[i] as tbutton).width*prw); (components[i] as tbutton).height:=round((components[i] as tbutton).height*prh); (components[i] as tlabel).Left:=round((components[i] as tlabel).Left*prw); (components[i] as tlabel).top:=round((components[i] as tlabel).top*prh); (components[i] as tlabel).width:=round((components[i] as tlabel).width*prw); (components[i] as tlabel).height:=round((components[i] as tlabel).height*prh); (components[i] as tpanel).Left:=round((components[i] as tlabel).Left*prw); (components[i] as tpanel).top:=round((components[i] as tlabel).top*prh); (components[i] as tpanel).width:=round((components[i] as tlabel).width*prw); (components[i] as tpanel).height:=round((components[i] as tlabel).height*prh); (components[i] as TGroupBox).Left:=round((components[i] as TGroupBox).Left*prw); (components[i] as TGroupBox).top:=round((components[i] as TGroupBox).top*prh); (components[i] as TGroupBox).width:=round((components[i] as TGroupBox).width*prw); (components[i] as TGroupBox).height:=round((components[i] as TGroupBox).height*prh); end; w:=form1.Width; h:=form1.Height; end; procedure TForm1.FormShow(Sender: TObject); begin w:=form1.Width; h:=form1.Height; end; end. Тут код для растягивания компонентов формы при изменении размеров программы... Данный код не работает, но если его писать только для tbutton, то все работает хорошо. Код:
if (components[i] is tbutton) then begin (components[i] as tbutton).Left:=round((components[i] as tbutton).Left*prw); (components[i] as tbutton).top:=round((components[i] as tbutton).top*prh); (components[i] as tbutton).width:=round((components[i] as tbutton).width*prw); (components[i] as tbutton).height:=round((components[i] as tbutton).height*prh); Помогите разобраться с проблемой. Необходимо чтобы все компоненты формы изменяли размер при изменении размера формы. Просто не могу найти ошибку. |