1.
procedure TForm1.ListBox2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if (Sender is TListBox) then
begin
listbox2.Items.add(listbox1.Items[listbox1.ItemIndex]);
listbox1.Items.Delete(listbox1.ItemIndex);
end;
end;
procedure TForm1.ListBox2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if (Sender is TListbox) then Accept:=True else Accept:=False;
end;
2.设置水平滚动条
procedure TForm1.SetHoScroolBar(Sender:TForm);
var
i,j,MaxWidth: integer;
begin
MaxWidth := 0;
for i:=0 to Sender.ComponentCount-1 do
begin
if Sender.Components is TCheckListBox then
begin
for j := 0 to (Sender.Components as TCheckListBox).Items.Count - 1 do
if MaxWidth < (Sender.Components as TCheckListBox).Canvas.TextWidth((Sender.Components as TCheckListBox).Items.Strings[j]) then
MaxWidth := (Sender.Components as TCheckListBox).Canvas.TextWidth((Sender.Components as TCheckListBox).Items.Strings[j]);
SendMessage((Sender.Components as TCheckListBox).Handle, LB_SETHORIZONTALEXTENT, MaxWidth+2, 0);
end;
end;
end;
3.listbox1的DragMode=dmAutomatic;
4.
单选:itemIndex
多选:哪些被选中 listbox1.Selected 做个循环