TStringGrid多选的复制与拷贝_Delphi教程

2006-02-04     评论:0条 进入论坛
  •   

uses Clipbrd;
function StringGridSelectText(mStringGrid: TStringGrid): string;
var
  I, J: Integer;
  S: string;
begin
  Result := '';
  if not Assigned(mStringGrid) then Exit;
  for J := mStringGrid.Selection.Top to mStringGrid.Selection.Bottom do
  begin
    S := '';
    for I := mStringGrid.Selection.Left to mStringGrid.Selection.Right do
      S := S + #9 + mStringGrid.Cells[I, J];
    Delete(S, 1, 1);
    Result := Result + S + #13#10;
  end;
end; { StringGridSelectText }
procedure StringGridPasteFromClipboard(mStringGrid: TStringGrid);
var
  vTextList: TStringList;
  vLineList: TStringList;
  I, J: Integer;
begin
  vTextList := TStringList.Create;
  vLineList := TStringList.Create;
  vLineList.Delimiter := #9;
  try
    vTextList.Text := Clipboard.AsText;
    for J := 0 to vTextList.Count - 1 do
    begin
      if J + mStringGrid.Row >= mStringGrid.RowCount then Break;
      vLineList.DelimitedText := vTextList[J];
      for I := 0 to vLineList.Count - 1 do
      begin
        if I + mStringGrid.Col >= mStringGrid.ColCount then Break;
        mStringGrid.Cells[I + mStringGrid.Col, J + mStringGrid.Row] := vLineList[I];
      end;
    end;
  finally
    vTextList.Free;
    vLineList.Free;
  end;
end; { StringGridPasteFromClipboard }
procedure StringGridCopyToClipboard(mStringGrid: TStringGrid);
begin
  Clipboard.AsText := StringGridSelectText(mStringGrid);
end; { StringGridCopyToClipboard }
procedure TForm1.MenuItemCopyClick(Sender: TObject);
begin
  StringGridCopyToClipboard(StringGrid1);
end;
procedure TForm1.MenuItemPasteClick(Sender: TObject);
begin
  StringGridPasteFromClipboard(StringGrid1);
end;
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if ssCtrl in Shift then
    case Key of
      Ord('C'): StringGridCopyToClipboard(TStringGrid(Sender));
      Ord('V'): StringGridPasteFromClipboard(TStringGrid(Sender));
    end;
end;

【声明】 http://www.Stuceo.com 版权与免责声明:本站转载其他媒体稿件是为传播更多的信息,此 类稿件不代表本站观点,本站不承担此类稿件侵权行为的连带责任。如您因版权等问题需要与本站联络,请联系 stuceo@163.com

讨论区
查看
已有 0 位对 此新闻感兴趣的网友发表了看法
今日推荐
 
news



热点推荐



中国学习基地
关于站点 - 意见反馈 - 广告服务 - 合作伙伴 - 程序支持 - 客户服务 - 联系我们

CopyRight 2006-2008, Stuceo.Com by 中国学习基地 Inc. All Rights Reserved .

鲁ICP备05047442号