怎样在TMemo组件上画图

dregs 2002-02-19 07:34:23
怎样在TMemo组件上画图
...全文
38 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiubolecn 2002-02-19
  • 打赏
  • 举报
回复
比较复杂,但可以欺骗
比如
Image1.Parent := Memo1;
Image1.Left := 10;
Image1.Top := 20;
Image1.Repaint;
dregs2002 2002-02-19
  • 打赏
  • 举报
回复
为了在TMemo组件表面画图,我们应当创造TMemo的子类,并重载它的drawing方法.具体做法如下:

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; // 生成临时TRect类型记录
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;
这个PaintImages过程在Memo的画布上画图象。

procedure TMyMemo.PaintImages;
var
MCanvas: TControlCanvas;
DrawBounds : TRect;
i, j : Integer;
OriginalRegion : HRGN;
ControlDC : HDC;
begin
MCanvas:=TControlCanvas.Create;
DrawBounds := ClientRect; // 生成临时TRect类型记录
try
MCanvas.Control:=Self;
ControlDC := GetDC ( Handle );
MCanvas.Draw(0, 1, Application.Icon);
finally
MCanvas.Free;
end;
end;

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧