点击水平滚动条后,按Button1显示最左边的列号,按Button2显示最右边的列号
procedure TForm1.Button1Click(Sender: TObject);
var
P: TPoint;
I: Integer;
begin
P.x := 1;
if dgIndicator in DBGrid1.Options then
P.x := P.x + IndicatorWidth;
P.y := 1;
I := DBGrid1.MouseCoord(P.x, P.y).x;
if dgIndicator in DBGrid1.Options then
ShowMessage(IntToStr(I - 1))
else ShowMessage(IntToStr(I));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
P: TPoint;
I: Integer;
begin
P.x := DBGrid1.ClientWidth - 1;
P.y := 1;
I := DBGrid1.MouseCoord(P.x, P.y).x;
if I < 0 then
ShowMessage(IntToStr(DBGrid1.FieldCount - 1))
else begin
if dgIndicator in DBGrid1.Options then
ShowMessage(IntToStr(I - 1))
else ShowMessage(IntToStr(I));
end;
end;