Author: Tomas Rutkauskas
I have THeaderControl with 4 sections. When I resize the first section, I need the
remaining 3 sections to resize proportionally to their size to ensure that they
don't go out of visibility (I mean that the last section end position always
remains the same). I tried to use OnSectionResize or OnSectionTrack events, but
without success. Can anyone help?
Answer:
1 2 procedure TForm1.ResizeMyHeader();
3 const4 MIN_COL_WIDTH = 10;
5 var6 iColWidth: Integer;
7 iColExtra: Integer;
8 iSection: Integer;
9 begin10 if HeaderControl1.Sections.Count > 1 then11 begin12 iColWidth := HeaderControl1.Width;
13 Dec(iColWidth, HeaderControl1.Sections[0].Width);
14 iColWidth := (iColWidth div (HeaderControl1.Sections.Count - 1));
15 iColExtra := HeaderControl1.Width - (HeaderControl1.Sections[0].Width +
16 (HeaderControl1.Sections.Count - 1) * iColWidth);
17 {resize the 2nd to the last columns}18 if iColWidth >= MIN_COL_WIDTH then19 begin20 for iSection := 1 to HeaderControl1.Sections.Count - 2 do21 begin22 HeaderControl1.Sections[iSection].Width := iColWidth;
23 end;
24 HeaderControl1.Sections[HeaderControl1.Sections.Count - 1].Width := iColWidth
25 + iColExtra;
26 end;
27 end;
28 end;
29 30 procedure TForm1.HeaderControl1_OnSectionResize(HeaderControl: THeaderControl;
31 Section: THeaderSection);
32 begin33 Self.ResizeMyHeader;
34 end;
35 36 procedure TForm1.Form_OnResize(Sender: TObject);
37 begin38 Self.ResizeMyHeader;
39 end;