![]() |
|
|
Регистрация | << Правила форума >> | 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... jmp $ ; Happy End! The Cake Is A Lie. |
Этот пользователь сказал Спасибо Bargest за это полезное сообщение: | ||
villipuk (10.01.2012)
|
#5
|
|||
|
|||
![]() Цитата:
Но тогда программа не запускается, выдает ошибку "Invalid class typecast". Это с чем может быть связано? |
#6
|
||||
|
||||
![]() Напишите свой полный код.
jmp $ ; Happy End! The Cake Is A Lie. |
Этот пользователь сказал Спасибо Bargest за это полезное сообщение: | ||
villipuk (10.01.2012)
|
#7
|
|||
|
|||
![]() А почему не используете якоря (Anchors) элементов? И ничего программировать не надо.
|
#8
|
|||
|
|||
![]() Свойства 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); |
#9
|
|||
|
|||
![]() Цитата:
Потому что, при растягивании формы компоненты друг на друга наезжают... |
#10
|
|||
|
|||
![]() Цитата:
и скрин надо было лучше кинуть, а не этот код |
#11
|
|||
|
|||
![]() Цитата:
Скрины приложил.... Там один стандарт, второй при уменьшении... третий при возвращении в исходный размер. И можно узнать про align'ы побольше от тебя? Ну может пример какой простой...? |
#12
|
||||
|
||||
![]() Судя по картинкам, ни о каком выравнивании (Align) речи не идёт, банальное изменение размеров контролов, что не есть хорошо для пользователя. На маленьком размере окна в контрол мышкой не попадёшь, при большом будут мозолить глаза. Лучше использовать Aligns/Anchors. Чтобы при чрезмерном уменьшении окна контролы не наезжали друг на друга, можно ограничить минимальный размер окна.
Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. |
#13
|
|||
|
|||
![]() Цитата:
И ведь максимальный размер можно ограничить чтобы не было деформации объектов на форме... Спасибо, бро!) |
#14
|
|||
|
|||
![]() Поставь вообще неизменяемый размер (Border - Single)
|
#15
|
||||
|
||||
![]() Код:
BorderStyle:=bsSingle; BorderIcons:=[biSystemMenu, biMinimize]; Пишу программы за еду. __________________ |