المشاركات : 18
المواضيع 11
:
: 0
الإنتساب : Jan 2009
كيف يمكن تحويل بيان في listbox الى listbox اخري باستخدام DRAG AND DROP وباستخدام DELPHI 6
ولكم الشكر
المشاركات : 2,293
المواضيع 157
:
: 81
الإنتساب : Dec 2008
هذا مثال صغير حول طريقة استعمال خاصية السحب والافلات (Drag & Drop)، ضع في مشروع جديد مكونين TListBox واكتب في الحدث OnDragOver والحدث OnDragDrop
لكلا المكونين ما يلي:
PHP كود :
procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Sender is TListBox;
end;
procedure TForm1.ListBox2DragDrop(Sender, Source: TObject; X, Y: Integer);
var
iTemp: Integer;
ptTemp: TPoint;
szTemp: string;
begin
{ change the x,y coordinates into a TPoint record }
ptTemp.x := x;
ptTemp.y := y;
{ Use a while loop instead of a for loop due to items possible being removed
from listboxes this prevents an out of bounds exception }
iTemp := 0;
while iTemp <= TListBox(Source).Items.Count-1 do
begin
{ look for the selected items as these are the ones we wish to move }
if TListBox(Source).selected[iTemp] then
begin
{ use a with as to make code easier to read }
with Sender as TListBox do
begin
{ need to use a temporary variable as when the item is deleted the
indexing will change }
szTemp := TListBox(Source).Items[iTemp];
{ delete the item that is being dragged }
TListBox(Source).Items.Delete(iTemp);
{ insert the item into the correct position in the listbox that it
was dropped on }
Items.Insert(itemAtPos(ptTemp, True), szTemp);
end;
end;
Inc(iTemp);
end;
end;
ولا تنسى أن تضبط الخاصية DragMode على dmAutomatic لكلا المكونين، أو أكتب مباشرة هذا الكود في الحدث OnCreate للنموذج الرئيسي:
PHP كود :
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.DragMode := dmAutomatic;
ListBox2.DragMode := dmAutomatic;
end;
ملاحظة: للكتابة في حدث معين لعدة مكونات دفعة واحدة، قم بتحديد (Select) مجموعة من المكونات وانقر مرتين في الحدث الذي تريد.
والسلام عليكم.
المشاركات : 778
المواضيع 97
:
: 0
الإنتساب : Nov 2008
بارك الله فيك اخي الكريم kachwahed
في الحقيقة ما شاء الله عليك...
امّا بخصوص الملاحظة
PHP كود :
ملاحظة: للكتابة في حدث معين لعدة مكونات دفعة واحدة، قم بتحديد (Select) مجموعة من المكونات وانقر مرتين في الحدث الذي تريد.
والسلام عليكم.
فهذا شئ جديد بنسة لي...
فشكرا لك كثيرا...
المشاركات : 18
المواضيع 11
:
: 0
الإنتساب : Jan 2009
بارك الله فيك اخي الكريم وجزاك الله كل خير