![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | 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); Помогите разобраться с проблемой. Необходимо чтобы все компоненты формы изменяли размер при изменении размера формы. Просто не могу найти ошибку. |
|
#2
|
|||
|
|||
|
Оо
А для этого нужно еще и код писать? Я удивлен, всегда думал что в палитре компонентов нажатием пары кнопок это все делается) |
|
#3
|
|||
|
|||
|
Цитата:
Ну допустим что так... тогда почему компаненты друг на друга при этом наезжают, а в моем коде нет? Вероятно код нужен... не просто же так помощи прошу. |
|
#4
|
||||
|
||||
|
Разумеется.
Код:
if (components[i] is tbutton) and (components[i] is tlabel) and (components[i] is TGroupBox) and (components[i] is tpanel) then Код:
if (components[i] is tbutton) then begin // тут для кнопок end else if (components[i] is tlabel) then begin // тут для Label end else... |
| Этот пользователь сказал Спасибо Bargest за это полезное сообщение: | ||
villipuk (10.01.2012)
| ||
|
#5
|
|||
|
|||
|
Цитата:
Но тогда программа не запускается, выдает ошибку "Invalid class typecast". Это с чем может быть связано? |
|
#6
|
||||
|
||||
|
Напишите свой полный код.
|
| Этот пользователь сказал Спасибо Bargest за это полезное сообщение: | ||
villipuk (10.01.2012)
| ||
|
#7
|
|||
|
|||
|
А почему не используете якоря (Anchors) элементов? И ничего программировать не надо.
|
|
#8
|
|||
|
|||
|
Цитата:
Потому что, при растягивании формы компоненты друг на друга наезжают... |
|
#9
|
|||
|
|||
|
Свойства Left,Top,Width и Height есть уже у TControl, поэтому
Код:
var C:TControl; .. if (Components[i] is TControl) then begin C:=TControl(Components[i]); C.Left:=round(C.Left*prw); C.Top:=round(C.Top*prh); C.Width:=round(C.Width*prw); C.Height:=round(C.Height*prh); |