2011-09-06 24 views
2

我需要用便接踵而來結構的工作:內部TGridPanel如何調整一個TGridPanel內TEDIT不使用alClient對準

TEDIT裏面TGdridPanel在別人的話,存在TGridPanel和的一個我需要插入其他TGridPanel的單元格。

在這個內部TGridPanel需要插入兩個TLabels和兩個TEdits,就像這樣:

______________________

| TLabel1 | TLabel 2 |

______________________

| TEdit 1 | TEdit 2 |

______________________

當我調整外部TGridPanel的大小時,內部格式也調整大小,因爲內部TGridPanel對齊設置爲alClient,並且當這種情況發生時,我想調整Label和Edit的樣子,如果它們被錨定在左側和右側,但它不會當它們在TGridPanel中時,如果我將這些內部組件的對齊設置爲alClient,它們就會失真。

我不能使用其他方式,因爲我在代碼中移動非常穩定,並且沒有權限更改它。

請有人幫助我嗎?

謝謝。

回答

1

使用內部TGridPanel的OnResize事件調整其子控件的大小,但不管您喜歡。如果您希望它們填充整個區域,請使用內部TGridPanel的ClientWidth/ClientHeight來幫助計算大小。

+0

此外,您可能是明智的,不要使用一個TGridPanel作爲內部控制,僅僅是因爲在你描述的情況下,你將會在整個時間內對抗它。在OnResize期間將其定義爲常規TPanel並操縱內部控件會容易得多。當然,例外情況是,如果您需要兩個以上的行或列,在這種情況下,TGridPanel可以提供幫助(但仍然不是必需的)。 –

3

的屏幕截圖,以確保這是你想要的......沒有代碼,只有設計是什麼?

enter image description here

enter image description here

object Form1: TForm1 
    Left = 0 
    Top = 0 
    Caption = 'Form1' 
    ClientHeight = 337 
    ClientWidth = 635 
    Color = clBtnFace 
    Font.Charset = DEFAULT_CHARSET 
    Font.Color = clWindowText 
    Font.Height = -11 
    Font.Name = 'Tahoma' 
    Font.Style = [] 
    OldCreateOrder = False 
    PixelsPerInch = 96 
    TextHeight = 13 
    object grdpnl1: TGridPanel 
    Left = 0 
    Top = 0 
    Width = 635 
    Height = 337 
    Align = alClient 
    Caption = 'grdpnlOutside' 
    ColumnCollection = < 
     item 
     Value = 33.333333333333340000 
     end 
     item 
     Value = 33.333333333333340000 
     end 
     item 
     Value = 33.333333333333340000 
     end> 
    ControlCollection = < 
     item 
     Column = 0 
     Control = lbl1 
     Row = 0 
     end 
     item 
     Column = 1 
     Control = lbl2 
     Row = 0 
     end 
     item 
     Column = 2 
     Control = lbl3 
     Row = 0 
     end 
     item 
     Column = 0 
     Control = lbl4 
     Row = 1 
     end 
     item 
     Column = 1 
     Control = grdpnlInside 
     Row = 1 
     end 
     item 
     Column = 2 
     Control = lbl5 
     Row = 1 
     end 
     item 
     Column = 0 
     Control = lbl6 
     Row = 2 
     end 
     item 
     Column = 1 
     Control = lbl7 
     Row = 2 
     end 
     item 
     Column = 2 
     Control = lbl8 
     Row = 2 
     end> 
    RowCollection = < 
     item 
     Value = 33.333333333333340000 
     end 
     item 
     Value = 33.333333333333340000 
     end 
     item 
     Value = 33.333333333333340000 
     end> 
    ShowCaption = False 
    TabOrder = 0 
    ExplicitLeft = 144 
    ExplicitTop = 64 
    ExplicitWidth = 273 
    ExplicitHeight = 105 
    object lbl1: TLabel 
     Left = 1 
     Top = 1 
     Width = 211 
     Height = 111 
     Align = alClient 
     Caption = 'lbl1' 
     ExplicitLeft = 91 
     ExplicitTop = 50 
     ExplicitWidth = 16 
     ExplicitHeight = 13 
    end 
    object lbl2: TLabel 
     Left = 212 
     Top = 1 
     Width = 211 
     Height = 111 
     Align = alClient 
     Caption = 'lbl1' 
     ExplicitWidth = 16 
     ExplicitHeight = 13 
    end 
    object lbl3: TLabel 
     Left = 423 
     Top = 1 
     Width = 211 
     Height = 111 
     Align = alClient 
     Caption = 'lbl1' 
     ExplicitWidth = 16 
     ExplicitHeight = 13 
    end 
    object lbl4: TLabel 
     Left = 1 
     Top = 112 
     Width = 211 
     Height = 111 
     Align = alClient 
     Caption = 'lbl1' 
     ExplicitWidth = 16 
     ExplicitHeight = 13 
    end 
    object grdpnlInside: TGridPanel 
     Left = 212 
     Top = 112 
     Width = 211 
     Height = 111 
     Align = alClient 
     Caption = 'grdpnlInside' 
     ColumnCollection = < 
     item 
      Value = 50.000000000000000000 
     end 
     item 
      Value = 50.000000000000000000 
     end> 
     ControlCollection = < 
     item 
      Column = 1 
      Control = pnlBottomRight 
      Row = 1 
     end 
     item 
      Column = 0 
      Control = pnlBottomLeft 
      Row = 1 
     end 
     item 
      Column = 0 
      Control = pnlTopLeft 
      Row = 0 
     end 
     item 
      Column = 1 
      Control = pnlTopRight 
      Row = 0 
     end> 
     RowCollection = < 
     item 
      Value = 50.000000000000000000 
     end 
     item 
      Value = 50.000000000000000000 
     end> 
     ShowCaption = False 
     TabOrder = 0 
     ExplicitLeft = 312 
     ExplicitTop = 168 
     ExplicitWidth = 185 
     ExplicitHeight = 41 
     object pnlBottomRight: TPanel 
     Left = 105 
     Top = 55 
     Width = 105 
     Height = 55 
     Align = alClient 
     BevelOuter = bvNone 
     Caption = 'pnlBottomRight' 
     ShowCaption = False 
     TabOrder = 0 
     ExplicitLeft = 136 
     ExplicitTop = 72 
     ExplicitWidth = 185 
     ExplicitHeight = 41 
     DesignSize = (
      105 
      55) 
     object edtRight: TEdit 
      Left = 0 
      Top = 17 
      Width = 105 
      Height = 21 
      Alignment = taRightJustify 
      Anchors = [akLeft, akRight] 
      TabOrder = 0 
      Text = 'edtRight' 
      ExplicitTop = 10 
     end 
     end 
     object pnlBottomLeft: TPanel 
     Left = 1 
     Top = 55 
     Width = 104 
     Height = 55 
     Align = alClient 
     BevelOuter = bvNone 
     Caption = 'pnlBottomRight' 
     ShowCaption = False 
     TabOrder = 1 
     ExplicitLeft = 136 
     ExplicitTop = 72 
     ExplicitWidth = 185 
     ExplicitHeight = 41 
     DesignSize = (
      104 
      55) 
     object edtLeft: TEdit 
      Left = 0 
      Top = 17 
      Width = 105 
      Height = 21 
      Anchors = [akLeft, akRight] 
      TabOrder = 0 
      Text = 'edtLeft' 
     end 
     end 
     object pnlTopLeft: TPanel 
     Left = 1 
     Top = 1 
     Width = 104 
     Height = 54 
     Align = alClient 
     BevelOuter = bvNone 
     Caption = 'pnlBottomRight' 
     ShowCaption = False 
     TabOrder = 2 
     ExplicitLeft = 136 
     ExplicitTop = 72 
     ExplicitWidth = 185 
     ExplicitHeight = 41 
     DesignSize = (
      104 
      54) 
     object lblLeft: TLabel 
      Left = 0 
      Top = 20 
      Width = 105 
      Height = 13 
      Anchors = [akLeft, akRight] 
      AutoSize = False 
      Caption = 'lblLeft' 
     end 
     end 
     object pnlTopRight: TPanel 
     Left = 105 
     Top = 1 
     Width = 105 
     Height = 54 
     Align = alClient 
     BevelOuter = bvNone 
     Caption = 'pnlBottomRight' 
     ShowCaption = False 
     TabOrder = 3 
     ExplicitLeft = 136 
     ExplicitTop = 72 
     ExplicitWidth = 185 
     ExplicitHeight = 41 
     DesignSize = (
      105 
      54) 
     object lblRight: TLabel 
      Left = 0 
      Top = 20 
      Width = 105 
      Height = 13 
      Alignment = taRightJustify 
      Anchors = [akLeft, akRight] 
      AutoSize = False 
      Caption = 'lblRight' 
     end 
     end 
    end 
    object lbl5: TLabel 
     Left = 423 
     Top = 112 
     Width = 211 
     Height = 111 
     Align = alClient 
     Caption = 'lbl1' 
     ExplicitWidth = 16 
     ExplicitHeight = 13 
    end 
    object lbl6: TLabel 
     Left = 1 
     Top = 223 
     Width = 211 
     Height = 113 
     Align = alClient 
     Caption = 'lbl1' 
     ExplicitWidth = 16 
     ExplicitHeight = 13 
    end 
    object lbl7: TLabel 
     Left = 212 
     Top = 223 
     Width = 211 
     Height = 113 
     Align = alClient 
     Caption = 'lbl1' 
     ExplicitWidth = 16 
     ExplicitHeight = 13 
    end 
    object lbl8: TLabel 
     Left = 423 
     Top = 223 
     Width = 211 
     Height = 113 
     Align = alClient 
     Caption = 'lbl1' 
     ExplicitWidth = 16 
     ExplicitHeight = 13 
    end 
    end 
end 
+0

+1使用Anchors = [akVertCenter] = [akLeft,akRight]。 – NGLN

+0

非常感謝!它的工作非常完美!好主意在每個網格單元格內插入面板。非常感謝你!!! –