Memo间文本拖动的问题,高分,解决马上给分(100)

  • 主题发起人 主题发起人 lzy6204
  • 开始时间 开始时间
L

lzy6204

Unregistered / Unconfirmed
GUEST, unregistred user!
1.将一个memo中的选中的文本拖放到另一个memo中的任意位置2.memo的选中文本 本身也可以拖动要求:拖到哪里,光标定位到哪里,拖放结束后插入文本,原选择文本被清除,类似dephi的编辑环境============================================我看大富翁论坛的回复框就有这样的功能,不知是如何实现的如果有其他控件可实现此功能也可以,麻烦告知是何控件,谢谢!
 
richedit能实现吗?如何实现
 
richedit之间好像本来就支持拖放但是不知道支持不支持其他控件向richedit拖放到任意位置有人做过吗
 
伤心啊,连个up的人都没有
 
在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 := Sender as TMyMemo; Src := Source as TMyMemo; 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;
 
编译没问题,但是效果差强人意
 
剪切->粘贴就OK啦~还搞得这么花哨干嘛~!
 
菜鸟黄有什么好办法没?》
 
后退
顶部