Delphi 7 - how to create a component with Text on the center of Image -
i have problem creating component. want have image , simple label on center of image. have component because create dynamically form code. how this? don't know how merge 2 components one.
if want implement own component fastest way might inherit timage, offer properties needed images , override paint method, accessing canvas of ancestor, not make chances on bitmap. short example not dealing stretch, have implement on own.
unit captionimage; interface uses windows, classes, controls, extctrls, graphics, pngimage, jpeg; type // maybe want more action on canvas without manipulation bitmap tonafterpaintevent = procedure(sender: tobject; canvas: tcanvas) of object; tgraphiccontrol = class(controls.tgraphiccontrol) // make canvas accessable public property canvas; end; tcaptionimage = class(extctrls.timage) private icanvas: tcanvas; fonafterpaint: tonafterpaintevent; function getfont: tfont; published public procedure paint; override; published property onafterpaint: tonafterpaintevent read fonafterpaint write fonafterpaint; property caption; property font: tfont read getfont; end; implementation function tcaptionimage.getfont: tfont; begin result := tgraphiccontrol(self).canvas.font; end; procedure tcaptionimage.paint; var s: string; r: trect; begin inherited; r := clientrect; s := caption; icanvas := tgraphiccontrol(self).canvas; icanvas.brush.style := bsclear; icanvas.textrect(r, s, [tfverticalcenter, tfcenter, tfsingleline]); if assigned(fonafterpaint) fonafterpaint(self, icanvas); end; end.
an example usage be:
procedure tform5.button1click(sender: tobject); begin tcaptionimage.create(self) begin parent := self; autosize := true; font.color := clblue; font.size := 20; picture.loadfromfile('c:\temp\bild 1.png'); caption := 'test'; end; end;
Comments
Post a Comment