Reputation: 429
I'm currently trying to resize components in my form but i can't figure it out how it works. I've tried OnResize and OnCanResize event but it won't change my component heigh or widht.
What i did until now is adding like fixed values to my heigh when the user is resizing but it doesn't resize the given component.
For example:
In my FormResize even i have something similar to:
procedure myform.FormResize(Sender TObject);
var
width: integer;
begin
width := grid.Width +100; //yes it only grows but it doesn't even work
grid.setBounds(grid.Left,grid.Top,width,grid.height);
end;
This doesn't work.
I also tried changing direcly with grid.Width := grid.Width +100
but it doesn't work either
I tried putting the same code in CanResize but same issue. I've tried with break points if it's the right event and if the procedure is being executed when i resize and yes it is. So i guess i missed something. My purpose is to resize the grid to keep the ratio to my form when ever a user resize/maximize the form.
So what is the proper way to resize a component?
Thank you.
object BDDTool: TBDDTool
Left = 0
Top = 0
Caption = 'BDD Manager'
ClientHeight = 303
ClientWidth = 680
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
Menu = mMainMenu
OldCreateOrder = False
Position = poScreenCenter
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object pnlFileManager: TPanel
Left = 8
Top = 8
Width = 665
Height = 289
BevelOuter = bvNone
TabOrder = 0
object Label1: TLabel
Left = 156
Top = 263
Width = 86
Height = 13
Caption = 'Primary key color:'
end
object Label2: TLabel
Left = 364
Top = 263
Width = 86
Height = 13
Caption = 'Foreign key color:'
end
object sgFilePreview: TStringGrid
Left = 143
Top = 23
Width = 514
Height = 234
Align = alCustom
ColCount = 1
Enabled = False
FixedCols = 0
RowCount = 2
TabOrder = 0
OnDrawCell = sgFilePreviewDrawCell
OnMouseDown = sgFilePreviewMouseDown
ColWidths = (
64)
RowHeights = (
24
24)
end
object btnConnectToDB: TButton
Left = 0
Top = 32
Width = 137
Height = 25
Caption = 'Connect to DB'
Enabled = False
TabOrder = 1
OnClick = btnConnectToDBClick
end
object btnCreateTabIncK: TButton
Left = 0
Top = 94
Width = 137
Height = 25
Caption = 'Create table (inc keys)'
Enabled = False
TabOrder = 2
OnClick = btnCreateTabIncKClick
end
object btnCreateTabGuidK: TButton
Left = 0
Top = 125
Width = 137
Height = 25
Caption = 'Create table (guid keys)'
Enabled = False
TabOrder = 3
end
object btnAscFk: TButton
Left = 0
Top = 156
Width = 137
Height = 25
Caption = 'Associate foreign keys'
Enabled = False
TabOrder = 4
OnClick = btnAscFkClick
end
object pnlFKColor: TPanel
Left = 456
Top = 263
Width = 81
Height = 18
TabOrder = 5
end
object btnDeconnectDB: TButton
Left = 0
Top = 63
Width = 137
Height = 25
Caption = 'Deconnect from DB'
Enabled = False
TabOrder = 6
OnClick = btnDeconnectDBClick
end
end
object pnlPKColor: TPanel
Left = 256
Upvotes: 0
Views: 4565
Reputation: 3801
Check you grid's Align property. If it's set something else to alNone then the resizing won't work as excepted.
Instead of OnResize try to use Anchors. Anchors will tell the component where its edges will "glued" inside its parent. If you set an empty Anchor [] it will remains always centered, if you set it to [akBottom, akRight] it will remains in the Bottom Right corner of its parent when the parent component is resized. If you set it to [akLeft, akTop, akRight, akBottom] then it will resize in vertically and horizontally too and maintains space between the parent's edges and its own.
If you use Anchors, you doesn't need the OnResize event for that.
Upvotes: 2