如何將 Label Drag 插入 RichEdit |
尚未結案
|
Sanyuan
一般會員 發表:24 回覆:32 積分:11 註冊:2002-06-23 發送簡訊給我 |
|
hahalin
版主 發表:295 回覆:1698 積分:823 註冊:2002-04-14 發送簡訊給我 |
從 http://delphi.about.com/cs/adptips2001/a/bltip0801_2.htm
挖來的,您參考看看囉...
function GetPosition(ARichEdit: TRichEdit): string var iX,iY : Integer; begin iX := 0; iY := 0; iY := SendMessage(ARichEdit.Handle, EM_LINEFROMCHAR, ARichEdit.SelStart,0) ; iX := ARichEdit.SelStart - SendMessage(ARichEdit.Handle, EM_LINEINDEX, iY, 0) ; Result := IntToStr(iY 1) ':' IntToStr(iX 1) ; end; |
Sanyuan
一般會員 發表:24 回覆:32 積分:11 註冊:2002-06-23 發送簡訊給我 |
謝謝您的答覆
不過還是不懂怎麼用耶
小弟的程式碼簡單如下
---------------------------------------
procedure TSetupFrm.Label1MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
if button=mbLeft then
Label1.BeginDrag(false);
end;
----------------------------------------
procedure TSetupFrm.RichEdit1DragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
accept:=true;
end;
----------------------------------------
procedure TSetupFrm.RichEdit1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var PosStr:String;
begin
RichEdit1.lines.Insert(0,TLabel(source).caption );
end;
---------------------------------------- 這樣只能插入到第一行
如何能插入 AAAA 與 BBBB之間呢?
煩請指教
|
hahalin
版主 發表:295 回覆:1698 積分:823 註冊:2002-04-14 發送簡訊給我 |
引言: --------------------------------------- procedure TSetupFrm.RichEdit1DragDrop(Sender, Source: TObject; X, Y: Integer); var PosStr:String; begin RichEdit1.lines.Insert(0,TLabel(source).caption ); end; ----------------------------------------你給0當然是插入第一行,你用我挖來的那段改一下,取得函數中的iy,再試看看吧! |
Sanyuan
一般會員 發表:24 回覆:32 積分:11 註冊:2002-06-23 發送簡訊給我 |
|
hahalin
版主 發表:295 回覆:1698 積分:823 註冊:2002-04-14 發送簡訊給我 |
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) RichEdit1: TRichEdit; Label1: TLabel; procedure RichEdit1DragDrop(Sender, Source: TObject; X, Y: Integer); procedure RichEdit1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure Label1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } public { Public declarations } end; function GetPosition(ARichEdit: TRichEdit): tpoint; var Form1: TForm1; implementation {$R *.DFM} function GetPosition(ARichEdit: TRichEdit): tpoint; var iX,iY : Integer; begin iX := 0; iY := 0; iY := SendMessage(ARichEdit.Handle, EM_LINEFROMCHAR, ARichEdit.SelStart,0) ; iX := ARichEdit.SelStart - SendMessage(ARichEdit.Handle, EM_LINEINDEX, iY, 0) ; result.x:=ix; result.y:=iy; //Result := IntToStr(iY 1) ':' IntToStr(iX 1) ; end; procedure TForm1.RichEdit1DragDrop(Sender, Source: TObject; X, Y: Integer); var PosStr:String; begin RichEdit1.lines.Insert(getposition(richedit1).y,TLabel(source).caption ); end; procedure TForm1.RichEdit1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin Accept:=true; end; procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if button=mbLeft then Label1.BeginDrag(false); end;發表人 - hahalin 於 2004/11/29 12:54:05 |
Sanyuan
一般會員 發表:24 回覆:32 積分:11 註冊:2002-06-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |