全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1373
推到 Plurk!
推到 Facebook!

如何將 Label Drag 插入 RichEdit

尚未結案
Sanyuan
一般會員


發表:24
回覆:32
積分:11
註冊:2002-06-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-29 00:15:46 IP:61.56.xxx.xxx 未訂閱
RichEdit 中已有一字串 ' AAAA BBBB CCCC' 使用DragDrop從 Label 到 RichEdit中 滑鼠移動在 AAAA 與 BBBB 中間想插入 但RichEdit此時並無游標可判定 請問應該如何處理?
hahalin
版主


發表:295
回覆:1698
積分:823
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-29 01:21:51 IP:218.170.xxx.xxx 未訂閱
從  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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-29 03:34:06 IP:61.56.xxx.xxx 未訂閱
謝謝您的答覆 不過還是不懂怎麼用耶 小弟的程式碼簡單如下 --------------------------------------- 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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-29 08:41:27 IP:218.170.xxx.xxx 未訂閱
引言: --------------------------------------- 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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-11-29 11:40:48 IP:211.75.xxx.xxx 未訂閱
謝謝 RichEdit1.lines.Insert(0,TLabel(source).caption ); 已經了解如何使用 不過,還是無法正確取得耶 >[>
hahalin
版主


發表:295
回覆:1698
積分:823
註冊:2002-04-14

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-11-29 12:51:35 IP:218.170.xxx.xxx 未訂閱
    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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-11-29 14:24:51 IP:211.75.xxx.xxx 未訂閱
謝謝 又另多學了Tpoint 感激
系統時間:2024-05-17 11:21:53
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!