Marco Cantù 1998, Mastering Delphi 4
Project: HDRSLIPT.DPR
Project Structure
HDRSLIPT.DPR
program HdrSlipt;
uses
Forms,
SplitF in 'SplitF.pas' {Form1};
{$R *.RES}
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
SPLITF.PAS
unit SplitF;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
ListBox3: TListBox;
FontDialog1: TFontDialog;
HeaderControl1: THeaderControl;
procedure ListBoxDblClick(Sender: TObject);
procedure HeaderControl1SectionResize(HeaderControl: THeaderControl;
Section: THeaderSection);
procedure FormResize(Sender: TObject);
procedure HeaderControl1SectionClick(HeaderControl: THeaderControl;
Section: THeaderSection);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ListBoxDblClick(Sender: TObject);
begin
with Sender as TListbox do
begin
FontDialog1.Font := Font;
if FontDialog1.Execute then
Font := FontDialog1.Font;
end;
end;
procedure TForm1.HeaderControl1SectionResize(HeaderControl: THeaderControl;
Section: THeaderSection);
begin
ListBox1.Width := HeaderControl1.Sections[0].Width;
ListBox2.Left := ListBox1.Width;
ListBox2.Width := HeaderControl1.Sections[1].Width;
ListBox3.Left := ListBox2.Width + ListBox2.Left;
ListBox3.Width := self.Width -
HeaderControl1.Sections[0].Width -
HeaderControl1.Sections[1].Width;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
ListBox2.Height := ListBox1.Height;
ListBox3.Height := ListBox1.Height;
HeaderControl1SectionResize(HeaderControl1,
HeaderControl1.Sections [0]);
end;
procedure TForm1.HeaderControl1SectionClick(HeaderControl: THeaderControl;
Section: THeaderSection);
begin
if Section = HeaderControl1.Sections[0] then
ListBox1.Sorted := True;
if Section = HeaderControl1.Sections[1] then
ListBox2.Sorted := True;
if Section = HeaderControl1.Sections[2] then
ListBox3.Sorted := True;
end;
end.
SPLITF.DFM
object Form1: TForm1
Left = 210
Top = 124
ActiveControl = ListBox1
AutoScroll = False
Caption = 'Split with a HeaderControl'
ClientHeight = 400
ClientWidth = 540
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 0
Top = 20
Width = 280
Height = 380
Align = alLeft
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -64
Font.Name = 'Arial'
Font.Style = []
ItemHeight = 72
Items.Strings = (
'Whale'
'Elephant'
'Rhino'
'Shark'
'Giraffe')
ParentFont = False
TabOrder = 0
OnDblClick = ListBoxDblClick
end
object ListBox2: TListBox
Left = 280
Top = 20
Width = 180
Height = 380
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -32
Font.Name = 'Arial'
Font.Style = []
ItemHeight = 36
Items.Strings = (
'Dog'
'Cat'
'Hen'
'Monkey'
'Cow'
'Bull'
'Hare'
'Sheep')
ParentFont = False
TabOrder = 1
OnDblClick = ListBoxDblClick
end
object ListBox3: TListBox
Left = 460
Top = 20
Width = 266
Height = 380
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -12
Font.Name = 'Arial'
Font.Style = []
ItemHeight = 15
Items.Strings = (
'Lizard'
'Ant'
'Shrimp'
'Bug'
'Bee')
ParentFont = False
TabOrder = 2
OnDblClick = ListBoxDblClick
end
object HeaderControl1: THeaderControl
Left = 0
Top = 0
Width = 540
Height = 20
Sections = <
item
MaxWidth = 400
MinWidth = 40
Text = 'Big list'
Width = 280
end
item
MaxWidth = 400
MinWidth = 40
Text = 'Medium list'
Width = 180
end
item
MaxWidth = 1000
MinWidth = 40
Text = 'Small list'
Width = 1000
end>
OnSectionClick = HeaderControl1SectionClick
OnSectionResize = HeaderControl1SectionResize
end
object FontDialog1: TFontDialog
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'System'
Font.Style = []
MinFontSize = 0
MaxFontSize = 0
Left = 488
Top = 336
end
end
Copyright Marco Cantù 1998