当用鼠标在StringGrid上拖动选择多个单元格,如何判断出哪几个单元格被选中?高手请指教。 我要实现用鼠标选择多个单元格,然后拖动,使单元格中的内容移动,怎么实现?当用鼠标在StringGrid上拖动选择多个单元格,如何判断出哪几个单元格被选中? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试下面的代码for i:=StringGrid1.Selection.Left to StringGrid1.Selection.Right do for j:=StringGrid1.Selection.Top to StringGrid1.Selection.Bottom do StringGrid1.Cells[i,j] :='Select'; unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids;type TForm1 = class(TForm) s1: TStringGrid; procedure s1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure s1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormCreate(Sender: TObject); procedure s1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } iLeft, iTop: Integer; iRight, iButtom: Integer; public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.s1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin s1.MouseToCell(X, Y, iLeft, iTop);end;procedure TForm1.s1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);var SS: TGridRect;begin if iLeft<0 then Exit; s1.MouseToCell(X, Y, iRight, iButtom); SS.Left:=iLeft; SS.Top:=iTop; SS.Right:=iRight; SS.Bottom:=iButtom; s1.Selection:=SS;end;procedure TForm1.FormCreate(Sender: TObject);begin iLeft:=-1;end;procedure TForm1.s1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin iLeft:=-1;end;end. WaitForSingleObject等待一个线程一段时间 项目总结 DBChart1问题 寻类似于outLook日历这样的控件 怎么装VCL组件。。 条形码打印控件哪里有下载??? 条码的校验位的生成规则是什么? 请教:如何使DBgrid控件的第一列成为固定列 喜欢助人为乐的朋友请进! TDecisionGraph的打印问题... 见者给分... 如何在菜单项上电击鼠标右键弹出其他快捷菜单? 如何将数据库中的数据以文本的形式(*.txt)输出?
for i:=StringGrid1.Selection.Left to StringGrid1.Selection.Right do
for j:=StringGrid1.Selection.Top to StringGrid1.Selection.Bottom do
StringGrid1.Cells[i,j] :='Select';
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;type
TForm1 = class(TForm)
s1: TStringGrid;
procedure s1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure s1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure s1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
iLeft, iTop: Integer;
iRight, iButtom: Integer;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.s1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
s1.MouseToCell(X, Y, iLeft, iTop);
end;procedure TForm1.s1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
SS: TGridRect;
begin
if iLeft<0 then Exit;
s1.MouseToCell(X, Y, iRight, iButtom);
SS.Left:=iLeft;
SS.Top:=iTop;
SS.Right:=iRight;
SS.Bottom:=iButtom;
s1.Selection:=SS;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
iLeft:=-1;
end;procedure TForm1.s1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
iLeft:=-1;
end;end.