procedure Tfrmqryconfig.btnBottClick(Sender: TObject);
begin
MoveSelectedItems('Bott');
end;
procedure Tfrmqryconfig.btnNextClick(Sender: TObject);
begin
MoveSelectedItems('Next');
end;
procedure Tfrmqryconfig.btnPreClick(Sender: TObject);
begin
MoveSelectedItems('Pre');
end;
procedure Tfrmqryconfig.btnTopClick(Sender: TObject);
begin
MoveSelectedItems('Top');
end;
procedure Tfrmqryconfig.MoveSelectedItems(act: string);
var
i,iMove:integer;
begin
if not (activecontrol is TListBox) then
begin
application.MessageBox('请选择列表框','提示',MB_OK);
exit;
end;
with TListBox(activecontrol) do
begin
if SelCount < 1 then exit;
if (act = 'Next') or (act = 'Bott') then
begin
if Selected[Items.Count-1] then exit;
iMove := 0;
for i := Items.Count - 1 downto 0 do
begin
if Selected then
begin
if act = 'Next' then
begin
if i < Items.Count - 1 then
begin
Items.Move(i,i+1);
Selected[i+1] := true;
end;
end
else
begin
if iMove = 0 then
iMove := Items.Count - 1 - i;
Items.Move(i,i+iMove);
Selected[i+iMove] := true;
end
end;
end; //for
exit;
end; //if (act = 'Next') or (act = 'Bott') then
if Selected[0] then exit;
iMove := 0;
for i:=0 to Items.Count - 1 do
begin
if Selected then
begin
if act = 'Pre' then
begin
if i > 0 then
begin
Items.Move(i,i-1);
Selected[i-1] := true;
end;
end
else if act = 'Top' then
begin
if iMove = 0 then
iMove := i;
Items.Move(i,i-iMove);
Selected[i-iMove] := true;
end;
end; //if Selected then
end; //for
end; //with
end;