首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Delphi FMX -如何停止TStringGrid的水平和垂直滚动

Delphi FMX -如何停止TStringGrid的水平和垂直滚动
EN

Stack Overflow用户
提问于 2019-03-25 19:10:50
回答 2查看 631关注 0票数 1

我有一个TStringGrid,但是如果我点击并拖动它,它可以垂直和水平平移,我不希望用户能够做到这一点,我如何才能阻止这种情况发生?

EN

回答 2

Stack Overflow用户

发布于 2019-03-26 08:18:32

您可以使用OnTopLeftChanged事件来捕捉任何类型的“滚动”发生的时间,并决定如何继续。如果您不希望用户在某些情况下超出范围,可以根据需要重新设置范围。这里有一个粗略的例子..。

uStringGridTestMain.dfm:

代码语言:javascript
复制
object frmStringGridTestMain: TfrmStringGridTestMain
  Left = 0
  Top = 0
  Caption = 'String Grid Test'
  ClientHeight = 416
  ClientWidth = 738
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object StringGrid1: TStringGrid
    Left = 72
    Top = 32
    Width = 513
    Height = 329
    Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine]
    TabOrder = 0
    OnTopLeftChanged = StringGrid1TopLeftChanged
    ColWidths = (
      64
      64
      64
      64
      64)
    RowHeights = (
      24
      24
      24
      24
      24)
  end
end

uStringGridTestMain.pas:

代码语言:javascript
复制
unit uStringGridTestMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids;

type
  TfrmStringGridTestMain = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1TopLeftChanged(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmStringGridTestMain: TfrmStringGridTestMain;

implementation

{$R *.dfm}

procedure TfrmStringGridTestMain.FormCreate(Sender: TObject);
begin
  StringGrid1.Align:= alClient;
  //Let's put a big scroll in both directions...
  StringGrid1.RowCount:= 50;
  StringGrid1.ColCount:= 50;
end;

procedure TfrmStringGridTestMain.StringGrid1TopLeftChanged(Sender: TObject);
begin
  //You can change the "current" cell...
  StringGrid1.Row:= 1;
  StringGrid1.Col:= 1;
  //Or you can change the scrolled cell on top-left...
  StringGrid1.TopRow:= 1;
  StringGrid1.LeftCol:= 1;
end;

end.
票数 1
EN

Stack Overflow用户

发布于 2020-08-18 16:06:13

要防止拖动时平移,可以将TStringGrid的TouchTracking属性设置为TBehaviorBoolean.False

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55336484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档