如何在memo中显示图片?(200分)

  • 主题发起人 主题发起人 tian0058
  • 开始时间 开始时间
T

tian0058

Unregistered / Unconfirmed
GUEST, unregistred user!
将图片作为memo的背景。
加入的文字还是可以显示的。
 
关注啊,,用OLE可以的,好像不能直接的,,
 
不知把图片当MEMO的前景行不行(图片设成透明)
 
我可以加入背景,可以文字下方还是白的。
 
我刚刚用RICHVIEW写了。可以实现。背景图上写文字。画新图。
去下载他。DEMO很完整
 
利用RxLib的RxRichEdit控件实现你的要求!

procedure TForm1.Button1Click(Sender: TObject);
var
Pict :TPicture;
begin
with OpenPictureDialog1 do begin
if Execute then begin
Pict := TPicture.Create;
try
Pict.LoadFromFile(FileName);
Clipboard.Assign(Pict);
RxRichEdit1.PasteFromClipboard;
finally
Pict.Free;
end;
end;
end;
end;

记得添加Clipbrd单元。
 
呵呵,我写的没有什么用,拿着玩儿吧:)
TCusMemo = class(TMemo)
private
FGraphic: TGraphic;
procedure Paint(var Msg: TMessage); message WM_PAINT;
published
property Graphic: TGraphic read FGraphic write FGraphic;
end;


procedure TCusMemo.Paint(var Msg: TMessage);
var
Canvas: TCanvas;
xCount, yCount: Integer;
x, y: Integer;
begin
inherited;

if not Assigned(Graphic) then Exit;
xCount := Trunc(Width / Graphic.Width + 1);
yCount := Trunc(Height / Graphic.Height + 1);

Canvas := TCanvas.Create;
Canvas.Handle := GetDC(Handle);

for x := 0 to Pred(xCount) do
for y := 0 to Pred(yCount) do
Canvas.Draw(x * Graphic.Width, y * Graphic.Height, Graphic);

ReleaseDC(Handle, Canvas.Handle);
Canvas.Free;
end;


调用
var
memo1: TCusMemo;
begin
memo1 := TCusMemo.Create(Self);
memo1.Parent := Self;
memo1.Top := 1;
memo1.Left := 1;
memo1.Width := 200;
memo1.Height := 150;
memo1.Graphic := Image1.Picture.Graphic;
end;
 
这个资料你看看???
用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;
 

to 网中戏
能告诉我在哪儿下载么?
to 远帆
试了一下,图片可以显示,不过显示文字的时候就会把图片冲掉了。不知道有没有办法解决。
to aimeoo
不知道RxLib是什么组件库,孤陋寡闻了,不好意思。
to app2001
我在《delphi高级编程》的书上看到过这段代码,可是看不太懂。

总之,谢谢大家的回答。本人接触Delphi时间不长,还希望高手们不吝赐教。
 
TO tian0058

www.Trichview.com 可以下载。是非常好的图文混排控件
 
后退
顶部