CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

如何在Memo里实现文本的拖放

楼主BattleBoy(独孤求败)2001-11-10 11:35:40 在 Delphi / VCL组件开发及应用 提问

问题点数:65、回复次数:1Top

1 楼Bob7946(X度空间)回复于 2001-11-10 11:36:00 得分 65

在Memo里实现文本的拖放  
   
  type  
      TMyMemo   =   class(TMemo)  
      private  
          FLastSelStart     :   Integer;  
          FLastSelLength   :   Integer;  
          procedure   WMLButtonDown(var   Message:   TWMLButtonDown);  
              message   WM_LBUTTONDOWN;  
      published  
          property   LastSelStart   :   Integer   read   FLastSelStart  
              write   FLastSelStart;  
          property   LastSelLength   :   Integer   read   FLastSelLength  
              write   FLastSelLength;  
      end;  
   
  Make   the   implementation   of   WMLButtonDown   look   like   this:  
   
  procedure   TMyMemo.WMLButtonDown(var   Message:   TWMLButtonDown);  
  var  
      Ch:Integer;  
  begin  
      if   SelLength>0   then  
      begin  
          Ch:=LoWord(Perform(EM_CHARFROMPOS,0,MakeLParam(Message.XPos,Message.YPos)));  
          LastSelStart:=SelStart;  
          LastSelLength:=SelLength;  
          if   (Ch>=SelStart)   and   (Ch<=SelStart+SelLength-1)   then  
              BeginDrag(True)  
          else  
              inherited;  
      end  
      else  
          inherited;  
  end;  
   
  Now,   install   this   component   into   a   package,   start   a   brand   new   project  
  in   Delphi   3   and   drop   two   TMyMemos   down.  
   
  Make   them   both   have   an   OnDragOver   event   handler   looking   like   this:  
   
  procedure   TForm1.MyMemo1DragOver(Sender,Source:TObject;X,Y:Integer;State:TDragState;var   Accept:Boolean);  
  begin  
      Accept:=Source   is   TMyMemo;  
  end;  
   
  Make   them   both   have   an   OnDragDrop   event   handler   looking   like   this:  
   
  procedure   TForm1.MyMemo1DragDrop(Sender,   Source:   TObject;X,Y:Integer);  
  var  
      Dst,Src:TMyMemo;  
      Ch           :Integer;  
      Temp       :String;  
  begin  
      Dst:=SenderasTMyMemo;  
      Src:=SourceasTMyMemo;  
      Ch:=LoWord(Dst.Perform(EM_CHARFROMPOS,0,MakeLParam(X,Y)));  
      if   (Src=Dst)   and   (Ch>=Src.LastSelStart)   and   (Ch<=Src.LastSelStart+Src.LastSelLength-1)   then  
          Exit;  
      Dst.Text:=Copy(Dst.Text,1,Ch)+Src.SelText+Copy(Dst.Text,Ch+1,Length(Dst.Text)-Ch);  
      Temp:=Src.Text;  
      Delete(Temp,Src.LastSelStart+1,Src.LastSelLength);  
      Src.Text:=Temp;  
  end;Top

相关问题

  • 悬赏!!!哪位高人能用WinAPI实现文本拖放!!!
  • 怎么实现将windows的文本文件拖放到Jtextarea中呢??
  • 将文本文件拖放文本框,并在文本框中自动打开该文件,谁知道其实现原理啊???
  • 如何实现可拖放功能,我原来用的是文本标签,用文本标签的位置记录打印位置
  • 如何实现拖放。
  • 如何实现拖放窗口?
  • 怎样实现图片的拖放???
  • 如何在sdk中实现ole拖放
  • 如何实现窗口中拖放.
  • 如何在DataGrid中实现拖放?

关键词

  • 文本
  • flastsellength
  • flastselstart
  • lastselstart
  • wmlbuttondown
  • lastsellength
  • tmymemo
  • twmlbuttondown
  • memo
  • sellength

得分解答快速导航

  • 帖主:BattleBoy
  • Bob7946

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo