TGridPanel做一个自动按比例缩放的窗体

object grdpnlAdd: TGridPanel
  Left = 0
  Top = 0
  Width = 466
  Height = 268
  Align = alClient  //重要
  BevelOuter = bvNone
  BorderWidth = 1
  Color = clWhite
  ColumnCollection = < //设定3列 设定比例
    item
      Value = 49.500000000000000000
    end
    item
      Value = 1.000000000000000000
    end
    item
      Value = 49.500000000000000000
    end>
  ControlCollection = <
    item
      Column = 0
      Control = pnlVehicleInfo //每个格子控制的容器
      Row = 0
    end
    item
      Column = 0
      Control = pnlTransportInfo
      Row = 2
    end
    item
      Column = 2
      Control = pnlCarrageUnit
      Row = 0
    end
    item
      Column = 2
      Control = pnlConsignUnit
      Row = 2
    end
    item
      Column = 0
      Control = pnl1CargoInfo
      Row = 4
    end
    item
      Column = 2
      Control = pnl1Hint
      Row = 4
    end>
  DoubleBuffered = True
  ExpandStyle = emFixedSize
  Locked = True
  Padding.Left = 1
  Padding.Top = 1
  Padding.Right = 1
  Padding.Bottom = 1
  ParentBackground = False
  ParentDoubleBuffered = False
  RowCollection = < //添加五行,设定比例
    item
      Value = 33.000000000000000000
    end
    item
      Value = 1.000000000000000000
    end
    item
      Value = 27.000000000000000000
    end
    item
      Value = 1.000000000000000000
    end
    item
      Value = 38.000000000000000000
    end>
  TabOrder = 0
  VerticalAlignment = taAlignBottom
  ExplicitTop = -24
  ExplicitWidth = 392
  ExplicitHeight = 225
  object pnlVehicleInfo: TPanel
    Left = 3
    Top = 3
    Width = 226
    Height = 85
    Align = alClient
    BevelOuter = bvNone
    BevelWidth = 2
    BorderWidth = 2
    Color = 16776180
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -14
    Font.Name = #24494#36719#38597#40657
    Font.Style = []
    ParentBackground = False
    ParentFont = False
    TabOrder = 0
    ExplicitWidth = 190
    ExplicitHeight = 70
    object grpVehicleInfo: TGroupBox
      Left = 2
      Top = 2
      Width = 222
      Height = 81
      Align = alClient
      Caption = ' '#36710#36742#20449#24687' '
      Font.Charset = ANSI_CHARSET
      Font.Color = clWindowText
      Font.Height = -14
      Font.Name = #24494#36719#38597#40657
      Font.Style = []
      ParentFont = False
      TabOrder = 0
      ExplicitWidth = 186
      ExplicitHeight = 66
    end
  end
  object pnlTransportInfo: TPanel
    Left = 3
    Top = 92
    Width = 226
    Height = 69
    Align = alClient
    BevelOuter = bvNone
    BevelWidth = 2
    BorderWidth = 2
    Color = 16776183
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -14
    Font.Name = #24494#36719#38597#40657
    Font.Style = []
    ParentBackground = False
    ParentFont = False
    TabOrder = 2
    ExplicitTop = 77
    ExplicitWidth = 190
    ExplicitHeight = 57
    object grpTransportInfo: TGroupBox
      Left = 2
      Top = 2
      Width = 222
      Height = 65
      Align = alClient
      Caption = ' '#36816#36755#20449#24687' '
      Font.Charset = ANSI_CHARSET
      Font.Color = clWindowText
      Font.Height = -14
      Font.Name = #24494#36719#38597#40657
      Font.Style = []
      ParentFont = False
      TabOrder = 0
      ExplicitWidth = 186
      ExplicitHeight = 53
    end
  end
  object pnlCarrageUnit: TPanel
    Left = 235
    Top = 3
    Width = 228
    Height = 85
    Align = alClient
    BevelOuter = bvNone
    BevelWidth = 2
    BorderWidth = 2
    Color = 16776183
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -14
    Font.Name = #24494#36719#38597#40657
    Font.Style = []
    ParentBackground = False
    ParentFont = False
    TabOrder = 1
    ExplicitLeft = 198
    ExplicitWidth = 191
    ExplicitHeight = 70
    object grpCarrageUnit: TGroupBox
      Left = 2
      Top = 2
      Width = 224
      Height = 81
      Align = alClient
      Caption = #22996#25176#21333#20301' '
      Font.Charset = ANSI_CHARSET
      Font.Color = clWindowText
      Font.Height = -14
      Font.Name = #24494#36719#38597#40657
      Font.Style = []
      ParentFont = False
      TabOrder = 0
      ExplicitWidth = 187
      ExplicitHeight = 66
    end
  end
  object pnlConsignUnit: TPanel
    Left = 235
    Top = 92
    Width = 228
    Height = 69
    Align = alClient
    BevelOuter = bvNone
    BevelWidth = 2
    BorderWidth = 2
    Color = 16776180
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -14
    Font.Name = #24494#36719#38597#40657
    Font.Style = []
    ParentBackground = False
    ParentFont = False
    TabOrder = 3
    ExplicitLeft = 198
    ExplicitTop = 77
    ExplicitWidth = 191
    ExplicitHeight = 57
    object grpConsignUnit: TGroupBox
      Left = 2
      Top = 2
      Width = 224
      Height = 65
      Align = alClient
      Caption = ' '#25215#36816#21333#20301' '
      Font.Charset = ANSI_CHARSET
      Font.Color = clWindowText
      Font.Height = -14
      Font.Name = #24494#36719#38597#40657
      Font.Style = []
      ParentFont = False
      TabOrder = 0
      ExplicitWidth = 187
      ExplicitHeight = 53
    end
  end
  object pnl1CargoInfo: TPanel
    Left = 3
    Top = 165
    Width = 226
    Height = 100
    Align = alClient
    BevelOuter = bvNone
    BevelWidth = 2
    BorderWidth = 2
    Color = 16776180
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -14
    Font.Name = #24494#36719#38597#40657
    Font.Style = []
    ParentBackground = False
    ParentFont = False
    TabOrder = 4
    ExplicitTop = 138
    ExplicitWidth = 190
    ExplicitHeight = 84
    object grpCargoInfo: TGroupBox
      Left = 2
      Top = 2
      Width = 222
      Height = 96
      Align = alClient
      Caption = ' '#36135#29289#20449#24687' '
      Font.Charset = ANSI_CHARSET
      Font.Color = clWindowText
      Font.Height = -14
      Font.Name = #24494#36719#38597#40657
      Font.Style = []
      ParentFont = False
      TabOrder = 0
      ExplicitWidth = 186
      ExplicitHeight = 80
    end
  end
  object pnl1Hint: TPanel
    AlignWithMargins = True
    Left = 238
    Top = 168
    Width = 222
    Height = 94
    Align = alClient
    BevelOuter = bvNone
    BevelWidth = 2
    BorderWidth = 2
    Color = 16776180
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -14
    Font.Name = #24494#36719#38597#40657
    Font.Style = []
    ParentBackground = False
    ParentFont = False
    TabOrder = 5
    ExplicitLeft = 201
    ExplicitTop = 141
    ExplicitWidth = 185
    ExplicitHeight = 78
  end
end

 

全选复制,粘贴到XE 的空窗体上即可。

添加行 控件的ColumnCollection属性右键添加 Add item

添加列 控件的RowCollection 属性右键添加 Add item

控制的格子ControlCollection 就自动出来了,在上面放panel等容器,然后通过这个属性选择容器对应受到哪个格子控制。

 

或者用代码控制

{grdpnlAdd.ColumnCollection.BeginUpdate;
grdpnlAdd.ColumnCollection[0].Value := 49.5;
grdpnlAdd.ColumnCollection[1].Value := 1;
grdpnlAdd.ColumnCollection[2].Value := 49.5;
grdpnlAdd.ColumnCollection.EndUpdate;
grdpnlAdd.RowCollection.BeginUpdate;
grdpnlAdd.RowCollection[0].Value := 32;
grdpnlAdd.RowCollection[1].Value := 1;
grdpnlAdd.RowCollection[2].Value := 32;
grdpnlAdd.RowCollection[3].Value := 1;
grdpnlAdd.RowCollection[4].Value := 33;
grdpnlAdd.RowCollection.EndUpdate; }

 

====更新 很多人碰到,

1、设定占多个格子

设定:从0行 0列开始 占两行 占两列。Control选中某一个 Twincontrol的类,如Tpanel

2、设定等比 ssPercent模式

 

 如果一开始Item2=0.  item0 1 各占50% ,那么如何让三个变成三等分呢? 把item2 Value设为50.这样  0 1 2 都为50,就会自动三等分,值也会自动调整为 33.3333

3、在使用过程中发现:这个控件不够完善,会丢失消息(底层的东西),上方的panel在大量频繁的缩放格子的时候 panel会调整不过来

 

 也可能不是gridpanel造成的,

 

posted @ 2016-09-01 10:29  海蓝7  阅读(531)  评论(0编辑  收藏  举报