我想给我程序中的Memo或RichEdit中加上图片,这样打字的时候,背景就可以是自己喜欢的图片了请大家赐教
解决方案 »
- 我开发了一个OCX,通过Twain调用扫描仪,里面接收不到消息,急救,拜托了
- 该段代码怎么简写,或者是怎样写代码少写?有没方法。散分,散分了。
- ---[散分]---庆祝今天登录CSDN,注销再登录N次,验证码都是88888
- 关于单引号
- Ihtmldocument2的问题?
- 有没有人在Dephi中用过MSHFlexGrid的?请教有关问题。
- 一个OOP的问题。重载父类方法
- 問一段有ClientDataSet代碼的CheckBrowseMode,IndexFieldnames,DisableControls分別是干什麼的??
- 挑战思路,如何虚拟出一个特定MAC地址
- 怎样把int强制转换成real,还有,反过来怎样?
- 存储过程老报找不到参数
- IdTCPServer和IdTCPClient,ServerSocket和ClientSocket,TcpServer和TcpClient的问题?
但是这个办法还是有问题,在敲入文字的时候,image1会发生滚动,闪烁的现象,作为背景还是不合适继续向大家请教!!!
unit ListViewMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs,
ComCtrls, ImgList;
type
TForm1 = class(TForm)
ListView1: TListView;
ImageList1: TImageList;
procedure ListView1CustomDraw(Sender:
TCustomListView;
const ARect: TRect; var DefaultDraw:
Boolean);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Bitmap1: TBitmap;
implementation
{$R *.DFM}
procedure TForm1.ListView1CustomDraw(Sender:
TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
var
x,y,w,h : LongInt;
begin
with Bitmap1 do begin
W := Width;
H := Height;
end;
Y := 0;
while Y < Height do begin
X := 0;
while X < Width do begin
ListView1.Canvas.Draw(X, Y, Bitmap1);
Inc(X, W);
end;
Inc(Y, H);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Bitmap1 := TBitmap.Create;
Bitmap1.LoadFromFile('backgray.bmp');
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Bitmap1.Free;
end;
end.
也不知道你能不能用上例程如下设Form1上控件RxRichEdit1和Button1。InsertBitmapIntoRxRichEdit使用方法请见Button1Click方法。unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, RxRichEd;type
TForm1 = class(TForm)
Button1: TButton;
RxRichEdit1: TRxRichEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses
JPEG;{$R *.dfm}function ConvertBitmapToRTF(const Bitmap: TBitmap): string;
var
bi, bb: string;
bis, bbs: Cardinal;
achar: string[2];
Buffer: string;
I: Integer;
type
PWord = ^Word;
begin
GetDIBSizes(Bitmap.Handle, bis, bbs);
SetLength(bi, bis);
SetLength(bb, bbs);
GetDIB(Bitmap.Handle, Bitmap.Palette, PChar(bi)^, PChar(bb)^);
SetLength(Buffer, (Length(bb) + Length(bi)) * 2);
i := 1;
for bis := 1 to Length(bi) do
begin
achar := IntToHex(Integer(bi[bis]), 2);
PWord(@Buffer[i])^ := PWord(@achar[1])^;
inc(i, 2);
end;
for bbs := 1 to Length(bb) do
begin
achar := IntToHex(Integer(bb[bbs]), 2);
PWord(@Buffer[i])^ := PWord(@achar[1])^;
inc(i, 2);
end;
Result := '{ tf1 {pictdibitmap ' + Buffer + ' }}';
end;procedure InsertBitmapIntoRxRichEdit(const Bitmap: TBitmap; const RxRichEdit:
TRxRichEdit); overload;
begin
RxRichEdit.SelText := ConvertBitmapToRTF(Bitmap);
RxRichEdit.SelLength := 0;
RxRichEdit.SelStart := RxRichEdit.SelStart + 1;
end;procedure InsertBitmapIntoRxRichEdit(const GraphicFileName: string; const
RxRichEdit: TRxRichEdit); overload;
var
Bitmap: TBitmap; Graphic: TPicture;
begin
Graphic := TPicture.Create;
try
Graphic.LoadFromFile(GraphicFileName); if Graphic.Graphic is TBitmap then
Bitmap := Graphic.Bitmap
else
begin
Bitmap := TBitmap.Create;
Bitmap.Assign(Graphic.Graphic);
end; InsertBitmapIntoRxRichEdit(Bitmap, RxRichEdit);
finally
if Bitmap <> Graphic.Bitmap then
FreeAndNil(Bitmap); FreeAndNil(Graphic);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
//InsertBitmapIntoRxRichEdit('C:TempUntitled.bmp', RxRichEdit1);
InsertBitmapIntoRxRichEdit('C:TempUntitled-8.jpg', RxRichEdit1);
RxRichEdit1.SetFocus;
end;
end.
以下代码我是通过获取memo设备句柄,然后改变其底色,改变背景原理应该是差不多的。
var
Back: TCanvas;
dc: HDC;
begin Back := TCanvas.Create;
dc := GetDC(Edit1.Handle);//获取Edit对应的dc
Back.Handle := dc;
Back.Brush.Color := clYellow;
Back.FillRect(Rect(0,0,100,100));
Back.Free;
TextOut(dc,0,0,PChar(Edit1.Text),length(Edit1.Text));//恢复被背景掩盖的内容
ReleaseDC(Edit1.Handle,dc);//释放dcend;
DHTMLEdithttp://lysoft.7u7.net