首页  编辑  

在MEMO中显示图像

Tags: /超级猛料/VCL/Memo&Edit&Richedit/Edit和Memo/   Date Created:

用Memo显示图片,你可以自己改改这个控件,处理memo的 WM_Paint消息,画个图片。

type

 TMyMemo = class(TMemo)

 protected

   procedure WMPaint(var Message: TWMPaint); message WM_PAINT;

 end;

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;

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;