delphi - How to access TFrame's canvas? -
using: delphi xe2, vcl 32-bit application, windows 8
i'm trying paint background of frame onto panel (i'm using tjvpanel, because exposes onpaint event) child control of frame.
after reading this post , adding canvas field, still not successful.
after calling showaddreceiptpanel, should draw frame's (tfrmmyframe) window contents controls on (which include grid , pagecontrol) on foreground panel, grayscaled, after being processed proeffectimage method, instead shows opaque white background. missing something?
here's code:
type tfrmmyframe = class(tframe) pnlhdr: tpanel; pnladdnewbg: tjvpanel; procedure pnladdnewbgpaint(sender: tobject); private { private declarations } fbgimg: tproeffectimage; fcnvs: tcanvas; procedure paintwindow(dc: hdc); override; procedure showaddreceiptpanel; procedure hideaddreceiptpanel; procedure resizepanel_pnladdnewbg; public { public declarations } constructor create(aowner: tcomponent); override; destructor destroy; override; end; constructor tfrmmyframe.create(aowner: tcomponent); begin inherited; fbgimg := tproeffectimage.create(nil); fcnvs := tcanvas.create; end; destructor tfrmmyframe.destroy; begin if assigned(fbgimg) fbgimg.free; if assigned(fcnvs) fcnvs.free; inherited; end; procedure tfrmmyframe.showaddreceiptpanel; begin resizepanel_pnladdnewbg; pnladdnewbg.visible := true; end; procedure tfrmmyframe.paintwindow(dc: hdc); begin inherited; fcnvs.handle := dc; end; procedure tfrmmyframe.pnladdnewbgpaint(sender: tobject); var l, t, w, h: integer; srct, drct: trect; begin // copy frame canvas bgimg bitmap l := 0; t := pnlhdr.height; w := clientwidth; h := clientheight - t; srct := trect.create(l, t, w, h); fbgimg.width := w; fbgimg.height := h; drct := trect.create(l, t, w, h); fbgimg.canvas.copymode := cmsrccopy; fbgimg.canvas.copyrect(drct, fcnvs, srct); // fbgimg.picture.savetofile('c:\tmp\a.bmp'); fbgimg.effect_antialias; fbgimg.effect_grayscale; // draw bgimg onto option panel tjvpanel(sender).canvas.copymode := cmsrccopy; tjvpanel(sender).canvas.draw(0, 0, fbgimg.picture.graphic); end; procedure tfrmmyframe.resizepanel_pnladdnewbg; var x1, y1, x2, y2: integer; bmp: tbitmap; begin x1 := 0; y1 := pnlhdr.height; x2 := clientwidth; y2 := clientheight - y1; pnladdnewbg.setbounds(x1, y1, x2, y2); end;
the dc assign canvas handle valid during paintwindow call. use outside function when not valid , hence behaviour observe.
i think should able solve problem calling paintto method. create bitmap of right size , pass canvas paintto.
Comments
Post a Comment