// Главная форма
frm=new TForm();
frm.Caption="JS+ - визуальный компонент TPaintBox";
frm.Width =525;
frm.Height=375;
// Строка состояния
stb=new TStatusBar(frm);
stb.SimpleText=" Вывод изображений с использованием контейнера PaintBox";
// Панель закладок
pgc=new TPageControl(frm);
pgc.SetBounds(10,10,frm.ClientWidth-20,stb.Top-20);
// Закладки
for (i=0;i<3;i++) {
tsh=new TTabSheet(pgc);
// Контейнер PaintBox
pbx=new TPaintBox(tsh);
pbx.Align=alClient;
pbx.OnPaint=pbx_Paint;
switch (i) {
case 0: tsh.Caption="Bitmap";
bmp=new TBitmap();
bmp.TransparentColor=clWhite;
bmp.Transparent=true;
bmp.LoadFromFile(JSPlus.HelpDir+"IMAGE\\TBitmap\\Image.bmp");
break;
case 1: tsh.Caption="Icon";
icn=new TIcon();
icn.LoadFromFile(JSPlus.HelpDir+"IMAGE\\TIcon\\Image.ico");
break;
case 2: tsh.Caption="Metafile";
mtf=new TMetafile();
mtf.LoadFromFile(JSPlus.HelpDir+"IMAGE\\TMetafile\\Image.emf");
}
}
frm.ShowModal();
// Обработчик события OnPaint
function pbx_Paint(pbx)
{
var img,x,y;
switch (pgc.ActivePageIndex) {
case 0: img=bmp; break;
case 1: img=icn; break;
case 2: img=mtf;
}
x=(pbx.Width -img.Width )/2;
y=(pbx.Height-img.Height)/2;
pbx.Canvas.Draw(x,y,img);
}