怎样在richEdit背景图片,不影响RichEdit其他编辑操作?看了网上的好多代码,都是不是很实在的。(最好不用三方控件)

解决方案 »

  1.   

    派生了一个新类,然后在里头处理WM_PAINT事件,这样可以在RichEdit
    的背景上放上一个图片
      

  2.   

    截取CM_CTLCOLOREDIT消息(必须override DefaultHandler过程), 在那里对传来的HDC画背景并返回一个Style为bsClear的Brush的Handle.
      

  3.   

    { TMyRichEdit }procedure TMyRichEdit.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);
             // Brush.Style:=bsClear;
              MCanvas.Draw(0,0,FormMain.Image1.Picture.Bitmap);
              Font.Color   :=   clRed;
              Brush.Style   :=   bsClear;
          end;
          finally
              MCanvas.Free;
          End;
      end;这是我写的类(参考网上的),图片是附加上去了,但是不能编辑(表现为字体看不见),更有闪烁现象.给点有用的代码吧.
      

  4.   

    如果你要试,还有一段代码:procedure TFormMain.FormCreate(Sender: TObject);
    const
     BitPath:string='meinv.bmp';
    var
     MyBitmap:TBitmap;
     MyRichEdit:TMyRichEdit;
    begin
      {SetWindowPos(Handle,HWND_TOP,Screen.Width-Width,Screen.DesktopTop,Width,Screen.Height-GetSysToolHeight,SWP_SHOWWINDOW);  //设置界面显示位置
      if FileExists(BitPath) then
      begin
        MyBitmap:=TBitmap.Create;
        MyBitmap.LoadFromFile(BitPath);
        RichEdit1.Brush.Bitmap:=MyBitmap;
      end;     RichEdit1.Brush.Bitmap:=image1.picture.bitmap;} MyRichEdit := TMyRichEdit.Create(self);
     MyRichEdit.Parent:=Panel4;
     MyRichEdit.Align:=alClient;
     MyRichEdit.Name:='MyRichEdit1';
     MyRichEdit.BorderStyle:=bsNone;
    end;
      

  5.   

    试过了,以前的帖子也是你这种情况,背景是加上了,可是文字却看不到
    要像你说的既能编辑还又要能像本身的背景估计有点费事,再琢磨一下,下面是我的代码procedure TForm1.DrawRichEditBG(Sender: TObject);
    var
          MyCanvas:TControlCanvas;
    Begin
          MyCanvas:=TControlCanvas.Create;
          Mycanvas.control:=RichEdit1;//想在RichEdit1上作画
          With   Mycanvas   do
          Begin
              //这里可以更改为你的作图程序
              Draw(0,0,image1.Picture.Graphic);
              Font.Color   :=   clRed;
              Brush.Style   :=   bsClear;
              TextOut(10,10,'在RichEdit中显示图片');
          end;
    end;
      

  6.   

    还有一个办法,设置一个string全局变量,每次用户输入的字符都保存到这个变量中
    每次都重画richedit的背景图片,并用TextOut输出保存的全局string变量
    但是很麻烦,需要判断用户输入是“删除、插入”等操作
      

  7.   

    这样就不是RichEdit了,变味了.呵呵.看到126邮箱不都是可以有那种信纸的格式吗?肯定是可以实现的.
      

  8.   

    用RichViewEdit吧,功能强大很多
      

  9.   

    RichViewEdit控件,网上没找到啊?能Email一份给我吗?
    E-mail:[email protected]
      

  10.   

    有支持Delphi的richviewedit吗?没用过这控件.我用的是D7.
      

  11.   

    RichViewEdt是在RichView控件包里面的,网上很多下载的
    http://down.zdnet.com.cn/link/2/13049.shtml
    我自己就在用,也是D7
      

  12.   

    我记得在那里看过,关于RichEdit网上有较多的说明啊,可以去参见.