Mega Code Archive

 
Categories / Delphi / Graphic
 

Drawing in TMemo

Title: Drawing in TMemo Question: How can I draw something on the TMemo? Answer: For drawing on TMemo surface we should create our component derived from TMemo and override its drawing. Something like this: type TMyMemo = class(TMemo) protected procedure WMPaint(var Message: TWMPaint); message WM_PAINT; end; And insert realisation of this procedure: procedure TMyMemo.WMPaint(var Message: TWMPaint); var MCanvas: TControlCanvas; DrawBounds : TRect; Begin inherited; MCanvas:=TControlCanvas.Create; DrawBounds := ClientRect; // Work with temporary TRect record. Try MCanvas.Control:=Self; With MCanvas do Begin Brush.Color := clBtnFace; FrameRect( DrawBounds ); InflateRect( DrawBounds, -1, -1); FrameRect( DrawBounds ); FillRect ( DrawBounds ); MoveTo ( 33, 0 ); Brush.Color := clWhite; LineTo ( 33, ClientHeight ); PaintImages; end; finally MCanvas.Free; End; end; The PaintImages procedure paint images on the Memo's canvas. procedure TMyMemo.PaintImages; var MCanvas: TControlCanvas; DrawBounds : TRect; i, j : Integer; OriginalRegion : HRGN; ControlDC : HDC; begin MCanvas:=TControlCanvas.Create; DrawBounds := ClientRect; // Work with temporary TRect record. try MCanvas.Control:=Self; ControlDC := GetDC ( Handle ); MCanvas.Draw(0, 1, Application.Icon); finally MCanvas.Free; end; end; Now you have your custom drawing memo.