我想给我程序中的Memo或RichEdit中加上图片,这样打字的时候,背景就可以是自己喜欢的图片了请大家赐教

解决方案 »

  1.   

    想了个办法,image1.parent:=RichEdit1;
    但是这个办法还是有问题,在敲入文字的时候,image1会发生滚动,闪烁的现象,作为背景还是不合适继续向大家请教!!!
      

  2.   

    看看这个吧,我想原理应该是一样的
    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. 
      

  3.   

    [转帖]在RxRichEdit中插入图片的完美解决方法(不使用剪贴板)
    也不知道你能不能用上例程如下设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.
      

  4.   

    谢谢zdq801104(我很笨,但是我不傻!) 和neo40(企鹅) 不过neo40(企鹅)的方法只是插入图片,不能使图片成为背景看了zdq801104(我很笨,但是我不傻!)的例程,可是RichEdit没有CustomDraw啊继续求教
      

  5.   

    基本原理应该是这样的:首先找到Memo或RichEdit的设备句柄,然后往上面画背景就可以了。
    以下代码我是通过获取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;
      

  6.   

    可能用IE的扩展会更好
    DHTMLEdithttp://lysoft.7u7.net