如何在listbox或MEMO控件中使用拖放技术(20分)

  • 主题发起人 主题发起人 xueminliu
  • 开始时间 开始时间
X

xueminliu

Unregistered / Unconfirmed
GUEST, unregistred user!
TABLE 和QUERY 控件的FIELDS EDIT里面可以对各个字段拖动以改变
字段的显示顺序,请问是否是在控件的STARTDRAG和ENDDRAG中处理,
我按照控件的帮助做但是没有成功,哪位大虾做过类似的程序.
 
listbox的例子如下,分给的太少了:))))
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
listbox1.begindrag(false);
end;

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
aPoint:TPoint;
begin
aPoint.x:=x;
aPoint.y:=y;
if (source is tlistbox) and (listbox1.ItemAtPos(apoint,true)<>-1)
and (listbox1.itematpos(apoint,true)<>listbox1.itemindex) then
accept:=true;
end;

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
aPoint:TPoint;
begin
aPoint.x:=x;
aPoint.y:=y;
listbox1.items.Exchange(listbox1.itemindex,listbox1.itematpos(aPoint,true));
end;

end.
 
无话可说了,只有select and ctrl-c 的份了。
 
hubdog无处不在,该说的他都说了.
 
接受答案了.
 
后退
顶部