Ver Mensaje Individual
  #7  
Antiguo 28-03-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Carmelo Cash.

Otra opción diferente, es usar un TPopupMenu con las opciones 'Cortar', 'Pegar' y 'Deshacer'. Y si lo deseas, con sus respectivos ShortCut como por ejemplo: Ctrl+C, Ctrl+V, Ctrl+Z.
Código Delphi [-]
...
var
  SL: TStrings;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SL := TStringList.Create;
  ListBox1.DragMode    := dmAutomatic;
  ListBox1.MultiSelect := True;
  ListBox1.PopupMenu   := PopupMenu1;
end;

procedure TForm1.Cortar1Click(Sender: TObject);
var
  i : Integer;
begin
  with TListBox(PopupMenu1.PopupComponent) do
  begin
    // Agregar items seleccionados al StringList
    for i := 0 to Count-1 do
      if Selected[i] then SL.AddObject(Items[i], TObject(i));
    // Eliminarlos del ListBox
    for i := Count -1 downto 0 do
      if Selected[i] then Items.Delete(i);
  end;
end;

procedure TForm1.Pegar1Click(Sender: TObject);
var
  CurrItem,i: Integer;
begin
  if SL.Count > 0 then
    with TListBox(PopupMenu1.PopupComponent) do
    begin
      CurrItem:= ItemIndex+1;
      // Insertar Items seleccionados
      Items.BeginUpdate;
      try
        for i :=  SL.Count-1 downto 0 do
          Items.Insert(CurrItem, SL[i])
        finally
          // Vaciar StringList
          SL.Clear;
          Items.EndUpdate
        end
    end;
end;

procedure TForm1.Deshacer1Click(Sender: TObject);
var
  i: Integer;
begin
  if SL.Count > 0 then
  begin
    // Restaurar items eliminados
    for i:= 0 to SL.Count-1 do
      ListBox1.Items.Insert(Integer(SL.Objects[i]),SL[i]);
    // Vaciar StringList
    SL.Clear
  end
end;

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  Cortar1.Enabled  := SL.Count = 0 ;
  Pegar1.Enabled   := not Cortar1.Enabled;
  Deshacer1.Enabled:= not Cortar1.Enabled;
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita