// Главная форма
frm=new TForm();
frm.Caption="JS+ - визуальный компонент THeaderControl";
frm.Width =600;
frm.Height=450;
// Строка состояния
stb=new TStatusBar(frm);
stb.SimpleText=
" Границы между секциями заголовка"+
" и сами заголовки интерактивны";
// Охватывающая панель
pn1=new TPanel(frm);
pn1.BevelInner=bvNone;
pn1.BevelOuter=bvLowered;
pn1.Top=100;
pn1.Height=frm.ClientHeight-pn1.Top*2;
// HeaderControl
hdc=new THeaderControl(pn1);
hdc.HotTrack=true;
hdc.Left=hdc.Top=1;
hdc.Height=TextHeight("Q")+6;
hdc.OnSectionClick=hdc_SectionClick;
hdc.OnSectionTrack=hdc_SectionTrack;
for (i=l=0;i<3;i++) {
// Секция HeaderControl
hds=new THeaderSection(hdc);
hds.Text="Секция "+(i+1);
hds.Width=hds.MinWidth=frm.TextWidth(hds.Text)+20;
hds.MaxWidth=hds.Width*2;
hds.numTag=i;
// Панель под секцией
pn2=hds.cmpTag=new TPanel(pn1);
pn2.Left=hdc.Left+l;
pn2.Top =hdc.Top+hdc.Height;
pn2.Width =hds.Width;
pn2.Height=pn1.ClientHeight-hdc.Height-hdc.Top*2;
pn2.Color=((i==1) ? 0xD9D9D9 : 0xF0F0F0).toTColor();
l+=(pn2.numTag=pn2.Width);
}
hdc.Width=l;
pn1.ClientWidth=hdc.Width+hdc.Left*2;
pn1.Left=(frm.ClientWidth-pn1.Width)/2;
frm.ShowModal();
// Обработчик события OnSectionClick
function hdc_SectionClick(hdc,hds)
{
// Исходная ширина секции
hds.Width=hds.cmpTag.numTag;
// Обработать новую ширину секции
hdc_SectionTrack(hdc,hds,tsTrackEnd);
}
// Обработчик события OnSectionTrack
function hdc_SectionTrack(hdc,hds,State)
{
var d,i,j=hds.numTag,l,n=hdc.Sections.Count;
var pn1=hdc.Parent,frm=pn1.Parent,pn2=hds.cmpTag;
if ((hds.Width<hds.MinWidth) || (hds.Width>hds.MaxWidth))
return;
// Приращение ширины секции
d=hds.Width-pn2.Width;
// Новая ширина панели под секцией
pn2.Width=hds.Width;
// Подравнять позиции панелей под секциями
for (i=j+1;i<n;i++)
hdc.Sections[i].cmpTag.Left+=d;
// Подравнять ширину охватывающей панели
for (i=l=0;i<n;i++)
l+=hdc.Sections[i].cmpTag.Width;
pn1.ClientWidth=(hdc.Width=l)+hdc.Left*2;
// Центрировать охватывающую панель
if (State==tsTrackEnd) {
pn1.Left=(frm.ClientWidth -pn1.Width )/2;
pn1.Top =(frm.ClientHeight-pn1.Height)/2;
}
}